What am I doing wrong?

(revised) First off. I am a total noob. Secondly, I can't figure out what I've done wrong with this code for calculating the amount of calories an individual needs to intake daily to maintain their weight. I don't think I did the braces thing correctly as someone attempted to explain how. I did, however change the formula needed to obtain the daily caloric intake needed.
I do believe someone is gonna have to hold my hand on this one and fix my code. OR better explain the braces for the if and else's. Also, an error message I receive is 26 [Error] 'Y' was not declared in this scope

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
 //Intermediate15.cpp - displays calorie intake needed for a specific person
//Created/revised by <Russell> on <2/25/2018>

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	//declare named constants and variables
	char sex = ' ';
	char active = ' ';
	double weight = 0.0;
	double calories = 0.0;
	
	//enter input items
	cout << "Enter your weight: ";
	cin >> weight;
	cout << "M(ale) or F(emale) : ";
	cin >> sex;
	if (toupper(sex) == 'M')
		char active = ' ';
		cout << "Are you moderately active? :";
		cin >> active;
		if (toupper(active) == Y)
		calories = weight * 15 * weight)
		else
		calories = weight * 13 * weight)
		//end if
	//end if
	else
		cout << "Are you moderately active? :";
		cin >> active
		if (toupper(active) == Y)
		calories = weight * 12 * weight)
		else
		calories = weight * 10 * weight)
		//end if
	//end else
	cout << "Your daily caloric intake should be: " << calories << endl;	
		
}
Last edited on
1
2
3
4
5
6
7
8
9
10
	if (toupper(sex) == 'M')
		char active = ' ';
		cout << "Are you moderately active? :";
		cin >> active;
		if (toupper(active) == Y)
		calories = weight(weight * 15)
		else
		calories = weight(weight *13)
		//end if
	//end if 


Your if-blocks and indentations* are wrong. Curly braces denote code blocks. If you want to execute multiple commands within an if-block, you have to wrap it in a set of curly braces { ... }.

1
2
3
if (something)
    do_this();
always_do_this();

vs.
1
2
3
4
5
6
if (something)
{
    do_this();
    do_that();
}
always_do_this();


*indentation doesn't matter to the compiler, but it does matter to any human being in terms of readability.
Last edited on
start by using brackets {}

if(some condition){
some code
}
else{
some code
}

http://www.cplusplus.com/doc/tutorial/control/
Y should be enclosed with ' '

you are also missing a lot of semi colons

also you should enclose your if statements and else statements in {} curly braces if they are more than one line
also another bug I noticed is

1
2
calories = weight(weight * 15);


weight is not a function it is a variable so it can not be used in this way,instead you would say

1
2
calories = weight * 15;


Topic archived. No new replies allowed.