Question

In: Computer Science

Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...

Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years) The calories needed for a man to maintain his weight is: BMR = 66 + (6.3 * weight in pounds) + (12.9 * height in inches) - (6.8 * age in years) A typical chocolate bar will contain around 230 calories. Write a program that allows the user to input their weight in pounds, height in inches, and age in years. Ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the female formula to calculate calories if “W” is entered. Ask the user if he or she is: A. Sedentary B. Somewhat active (exercise occasionally) C. Active (exercise 3-4 days per week) D. Highly active (exercise every day) If the user answers “Sedentary” then increase the calculated BMR by 20 percent. If the user answers “Somewhat active” then increase the calculated BMR by 30 percent. If the user answers “Active” then increase the calculated BMR by 40 percent. Finally, if the user answers “Highly active” then increase the calculated BMR by 50 percent. The program should then output the number of chocolate bars based on the BMR value that should be consumed to maintain one’s weight for both a woman and a man. Input Errors If the user enters an age either < 1 or > 100, instantly end the program with an error message. If the user enters a height < 10 or > 100, instantly end the program with an error message. If the user enters a weight < 10 or > 500, instantly end the program with an error message. You can assume that the user does not type some non-numeric value. You don't have to test for this kind of non-numeric error. If the user does not enter ‘M' for male calculation or 'F' for female calculation, instantly end the program with an error message. If the user does not enter A, B, C, or D when prompted, instantly end the program with an error message. These limits must be defined as symbolic constants, which should be used throughout the program. Submit at least three sample runs that show possible run-time errors. Also demonstrate the capacity to get a single letter from the user, showing at least one user-input error (an illegal choice) and one bad numeric input (out-of-range error).

Solutions

Expert Solution

using namespace std;

int main()

{

int age,bar;

char sex,a;

float wt,ht,bmr;

printf("\nEnter your sex:'M' for Male and 'F' for female:=");

scanf("%c",&sex);

if(sex!='M'&& sex!='m' && sex!='F' && sex!='f')

printf("\You have entered wrong input!!");

else{

printf("Enter your age:=");

scanf("%d",&age);

if(age<1 || age>100)

printf("You have entered wrong input!!");

else

{

printf("Enter your height in inches:=");

scanf("%f",&ht);

if(ht<10 || ht>100)

printf("You have entered wrong input!!");

else

{

printf("Enter your weight in pounds:=");

scanf("%f'",&wt);

if(wt<10 || wt>500)

printf("You have entered wrong input!!");

else

{

if(sex=='M' || sex=='m')

{

bmr=655+(4.3*wt)+(4.7*ht)-(4.7*age);

}

else

{

bmr=66+(6.3*wt)+(12.9*ht)-(6.8*age);

}

printf("Your basal metabolic rate is=%f",bmr);

printf("\nEnter your activity:\nA.Sedentary\nB.Somewhat Active\nC.Active(Exercise 3-4)days\nD.Highly Active(Exercise Everday)\nPlease enter:=");

scanf("%c",&a);

if(a!='A'&& a!='B'&& a!='C'&& a!='D')

printf("You have entered Wrong input!!");

else

{

if(a=='A')

bmr=bmr+(0.2*bmr);

if(a=='B')

bmr=bmr+(0.3*bmr);

if(a=='C')

bmr=bmr+(0.4*bmr);

if(a=='D')

bmr=bmr+(0.5*bmr);

printf("\nYou new bmr based on your activity is:=%f",bmr);

bar=(bmr/230);

printf("\n\nBased on your bmr,You can have %d chocolate bar in a day to maintain your weight",bar);

}

}

}

}

}

return 0;

}

******"""""""""**********"""""""""""


Related Solutions

Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This...
Python code Assignment Overview In this assignment you will practice with conditionals and loops (for). This assignment will give you experience on the use of the while loop and the for loop. You will use both selection (if) and repetition (while, for) in this assignment. Write a program that calculates the balance of a savings account at the end of a period of time. It should ask the user for the annual interest rate, the starting balance, and the number...
C++ program to read line comments. This assignment will give you a little bit of practice...
C++ program to read line comments. This assignment will give you a little bit of practice with string parsing. Your task is to write a program that reads in a .cpp file line-by-line, and prints out only the text that's after the // characters that indicate a single-line comment. You do not have to worry about /* multiline comments */ though there will be a small amount of extra credit for programs that correctly extract these comments as well.
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please...
This assignment is to give you practice using struts, arrays, and sorting. (Objective C++ and please have a screenshot of output) In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores,...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value...
Programming Assignment #3: SimpleFigure and CirclesProgram Description:This assignment will give you practice with value parameters, using Java objects, and graphics. This assignment has 2 parts; therefore you should turn in two Java files.You will be using a special class called DrawingPanel written by the instructor, and classes called Graphics and Color that are part of the Java class libraries.Part 1 of 2 (4 points)Simple Figure, or your own drawingFor the first part of this assignment, turn in a file named...
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output)...
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output) cycle that is the heart of many imperative programs used for processing large amount of data. Daisy is recently hired by a warehouse. One of her job is to keep track the items ordered by all the branches of the company. The company wants to automate the task using a computer program. Being a friend of Daisy, she knows you are a Computer Science...
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the...
JAVA PROGRAMMING Objectives JAVA Practice incremental development. Practice getting input from and printing output for the user. Write a program with conditional statements. Write a program with loops. Specifications Think of three countries you’d like to travel to and look up the conversion rate between dollars and the money used in those countries. (See http://www.ratesfx.com/ rates/rate-converter.html for conversion rates.) Write a program that will convert money from dollars into each of those three types of currency, or from one of...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the...
Programming II: C++ - Programming Assignment Fraction Object with Operator Overloads Overview In this assignment, the student will write a C++ program that implements a “fraction” object. When writing the object, the student will demonstrate mastery of implementing overloaded operators in a meaningful way for the object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Mathematical Modeling - Fractions · Operator Overloading – Binary Operators (Internal Overload) · Operator Overloading – Binary Operator (External...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write...
Programming II: C++ - Programming Assignment Vector Overloads Overview In this assignment, the student will write a C++ program that overloads the arithmetic operators for a pre-defined Vector object. When completing this assignment, the student should demonstrate mastery of the following concepts: · Object-oriented Paradigm · Operator Overloading - Internal · Operator Overloading - External · Mathematical Modeling Assignment In this assignment, the student will implement the overloaded operators on a pre-defined object that represents a Vector. Use the following...
In Coral Code Please!!!! The assignment is to get an integer from input, and output that...
In Coral Code Please!!!! The assignment is to get an integer from input, and output that integer squared, ending with newline. (Note: This assignment is configured to have students programming directly in the zyBook. Instructors may instead require students to upload a file). Below is a program that's been nearly completed for you. Click "Run program". The output is wrong. Sometimes a program lacking input will produce wrong output (as in this case), or no output. Remember to always pre-enter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT