In: Computer Science
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).
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;
}
******"""""""""**********"""""""""""