In my computer science I class I am having trouble making my program make decisions, in this project, the program has to decide whether the user is male or female and run a specific formula depending on whether the user entered male or female. These is the exact requirements for the project. A typical chocolate bar will contain around 230 calories. Write a program that allows the user to input his or her weight in pounds, height in inches, age in years, and the the character m for male and f for female. the program should then output the number of chocolate bars that should be consumed to maintain one's weight for the appropriate sex of the specified weight, height, and age. I have spent quite some time trying to figure this out and came to the conclusion that I need some help! Not asking for the answer to be given to me but just for some assistance. Below is what code I have put in, I am using a g++ compiler
You declared gender as an integer, but what integer should I possibly put in to show I am male or female? This would be better as a char (so I can put in 'm' or 'f') or as a string (so I can put in "male" or "female").
if(gender = male) - Using a single equals sign is assignment. To do comparison, a double equals sign is used. if(gender = 1) This would assign the number 1 to the variable gender.
if(gender == 1) This would compare if gender is equal to 1.
Also note that if you use char for gender, chars must be compared in single quotes.
char gender = 'm';
if(gender == 'm')
And if you use a string, they must be put in double quotes. ""
string gender = "female";
if(gender == "female")
Do not include anything else in the brackets after else, or any brackets at all. Else is just every case which fails the if statement(s). Also, check your sum for female case. I suspect a maths error.