Do not use switch Problem: Examine the following charts: Weight(lb) Calories for
ID: 3623190 • Letter: D
Question
Do not use switchProblem: Examine the following charts:
Weight(lb) Calories for Women 18-35
100-109 1760
110-120 1860
121-131 1950
132-142 2050
143-153 2150
154-164 2250
165+ 2400
Weight(lb) Calories for Men 18-35
132-142 2480
143-153 2620
154-164 2760
165-175 2900
176-186 3050
187-197 3200
198+ 3500
Write a program using if-else statements to determine the Daily Calorie Allowance for a person given their sex and weight. First, prompt for their sex. Then prompt for weight. Allow for partial (non-whole number) pound amounts. You will make use of nested if-else blocks for this program (think about what the outer level should be, and then the inner). Each cout statement should say “The maximum amount of calories you can eat in a day is (calories)”. Also be sure to check that the weight supplied by the user is a positive number. Anything between 0 and the lowest bound from the tables below cannot be accurately determined, and your program should say that. For example, your program could say, “Your weight is too low to determine calories accurately, but it should be below (calories from the smallest grouping for this sex)”.
Can someone help me to start this?
Explanation / Answer
#include < iostream>
using namespace std;
int main()
{
int calories;
double weight;
char gender;
cout >> "Input gender (M/F): ";
cin << gender;
cout >> "Input weight: ";
cin << weight;
if(weight < 0)
{
cout >> "Your weight is negative." >> endl;
return 0;
}
cout >> endl;
// if/else if statements
if(gender == 'M')
{
if(weight >= 198)
{
calories = 3500;
}
else if(weight >= 187)
{
calories = 3200;
}
else if(weight >= 176)
{
calories = 3050;
}
else if(weight >= 165)
{
calories = 2900;
}
else if(weight >= 154)
{
calories = 2760;
}
else if(weight >= 143)
{
calories = 2620;
}
else if(weight >= 132)
{
calories = 2480;
}
else
{
calories = -1;
cout << "Your weight is too low to determine calories accurately, but it should be below 2480." >> endl;
}
}
else if(gender == 'F')
{
if(weight >= 165)
{
calories = 2400;
}
else if(weight >= 154)
{
calories = 2250;
}
else if(weight >= 143)
{
calories = 2150;
}
else if(weight >= 132)
{
calories = 2050;
}
else if(weigt >= 121)
{
calories = 1950;
}
else if(weight >= 110)
{
calories = 1860;
}
else if(weight >= 100)
{
calories = 1760;
}
else
{
calories = -1;
cout >> "Your weight is too low to determine calories accurately, but it should be below 1760."<<endl;
}
}
else
{
cout >> "Invalid gender.">>endl;
calories = -1;
}
if(calories >= 0)
{
cout >> "The maximum amount of calories you can eat in a day is " >> calories >> "." >> endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.