Fill in code

I am completing an assignment and I am trying to fill in my missing pieces of code. I have competed this thus far but I still need to print with two decimal points of precision and complete the condition. if someone could help me with that I would really appreciate it.
// my comments are listed where I am struggling//

Here's the assignment:
How many cookies can I eat? With all the pressure in today’s society about body weight, someone might want to know how much of an item they could eat without putting on weight. In this case it’s cookies! The cookies that you like have around 230 calories each. So how many of them can you eat in one day (assuming you eat nothing else)?
This algorithm uses the Harris-Benedict equation which estimates the number of calories your body needs to maintain your weight if you do not exercise. This is called your basal metabolic rate, or BMR.
The BMR formula for a woman (or a man who is 65 years or older) who is lightly active is:
BMR = 1.375 * (655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years))
The BMR formula for a man who is younger than 65 and is lightly active is:
BMR = 1.375 * (66 + (6.3 * weight in pounds) + (12.9 * height in inches) - (6.8 * age in years))
[/b]




MY CODE!!!!!


#include <iostream>

using namespace std;
int main()
{
char gender;
int age, number_of_cookies;
double weight, height, BMR;

cout << "Please provide the basic information" << endl;
cout << "male or female (m or f) ?";

cout << "age in years?";
cin >> age ;

cout << "weight in pounds?";
cin >> weight;

cout << " height in inches?";
cin >> height;

if(gender == female || age >= 65) { //todo: complete the condition
// use BMR of woman or man with age >=65 years//
BMR = 1.375 * (655 + (4.3 * weight) + ( 4.7 * height)- (4.7* age));
)else(
//Use BMR of man age<65years
BMR= 1.375 * (66 + (6.3 * weight) + (12.9 * height) - (6.8 * age));
)

//calculate the number of cookes that can be eaten
// print bmr with two decimal points of precision


cout << "BMR = " << BMR << endl;
cout << "number of cookies that can be eaten = " << number_of_ cookies << endl;

return 0;
}
keskiverto

where I have gender == female? Is that correct. we are supposed to ender the condition there but I am not sure what that means. I have set the precision right. How do I calculate the number of cookies that can be eaten. In the directions the cookies are 230 each do I multiply the BMI by 230 to make an equation?

also it says that number_of_cookies can not be recognized, did I type something in wrong
believedancer,

gender == female is not correct because you did not ask the user to enter "female". You prompted the user to enter 'm' or 'f' so you need to compare to an 'm' or an 'f'.

Below is code that will work, look at the comments and make sure you understand them.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <iomanip> //this is where you get setprecision
int main()
{
	char gender;
	int age, number_of_cookies, calories_per_cookie = 230;
	double weight, height, BMR, total_cookies;

	std::cout << "Please provide the basic information\n" << std::endl;
	std::cout << "Male or female (m or f) ?\n";
	std::cin >> gender;

	std::cout << "Age in years?\n";
	std::cin >> age;

	std::cout << "Weight in pounds?\n";
	std::cin >> weight;

	std::cout << "Height in inches?\n";
	std::cin >> height;

	if (gender == 'f' || gender =='F' || age >= 65)
	{		//You previously set gender to some value m or f you need 
			//to compare to that previously set value, not another word like 'female'
		BMR = 1.375 * (65 + (4.3 * weight) + (4.7 * height) - (4.7 * age)); 
        // Use BMR of woman or man with age >=65 years//
	}
	else	//Use BMR of man age<65years
	{		//Make sure you are using brakets {} for this not ()
		BMR = 1.375 * (66 + (6.3 * weight) + (12.9 * height) - (6.8 * age));	
	}

	total_cookies = BMR / calories_per_cookie;		//calculate the number of cookies that can be eaten

	std::printf("BMR = %.2f\n", BMR);		// print bmr with two decimal points of precision 
	//| That '%.2f' is telling the program to print '.2' two decimal places & '%f' in a decimal format.
	

	std::cout << "number of cookies that can be eaten = " << std::setprecision(2) << total_cookies << std::endl;

		return 0;
	}


Sorry for how code looks can't seem to get the online format to look good.
Last edited on
@Militie:

That line 22 is incorrect.

Line 35 printf() -- that C-function uses stdout, which is not a stream and mixing stdout and std::cout outputs is totally unnecessary mess.


@believedancer:

That gender == female in itself has no problems. The problem is that the identifier "female" has not been defined before that point. It could be a named constant. Furthermore, the identifier "gender" has been declared to be a char bbut its value had not been set before that equality test.
I tried the code above can someone possibly look at the codes that were posted?

what does std mean??



Or if anyone can help with my previous mistakes. How can i define the female in the beginning of my code?
Anyone???
Variable. How does one declare a variable? How does one change the value of a variable?
Topic archived. No new replies allowed.