If the user enters A or B, the user enters the height and weight, it then prints the condition of low, target, or high. The program should be in a loop that until the user chooses C, the program will again ask for more input. I can not for the life of me figure this out. What am I doing wrong?
I apologize for any standard programming rules being broken. This is for school and I am very new at this. Here is my code:
don't use while(sex != 'C')! That would not work. You have to declare a bool variable and set the value to true. Also, if I were you, I'd use a do-while-loop.
1 2 3
do{
//whatever
}while(/*something*/);
Because there, you always have at least one execution of the loop. It doesn't make sense if you start the program that you stop it as the first step.
Actually the while loop will work just fine as it's written, but you need to get input inside the loop. If you keep the logic the way it is now, just get input at the bottom of the loop for the sex/quit info. The code prompting for height and weight should go before the first if statement in the loop (or leave it where it is and duplicate it inside the else if ( sex == 'B' ) block.)
Also, on lines 24, 29, 37, 42, 52, 57, 63 and 68 you use = when you should be using == for comparison.
I still can't get it to work. I still do not know what I am doing wrong. It seems to be just repeating the A option over and over, no matter what letter you pick initially. Did I do it correctly? If not, what did I do wrong?
You may get the results you're getting if you weren't using capital letters as the input. But even if you did, your checking is being done wrong. Like in if (height == 58 || height <= 64), entering ANY number up to 64, including negative numbers, would register as true. A -10 IS less than or equal to 64. What you need is if (height >= 58 && height <= 64), which is if height is higher or equal to 58 AND height is less than or equal to 64. The same with the other checking in the program. Your program should look more like this:
omg, thanks a lot everyone. You were more help than my professor was. I have sent email after email...no answer. I appreciate all the help and thanks again. ^^