If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

trouble with while statements...what am i missing?

Im trying to create a program that has the user input a 5 digit number. If it's between 10000 & 99999, it will do one thing..(just saying 'yes' for now. Outside those numbers will prompt the user to input again. However, if the user inputs the exact digits 76087, it should display 'term'.

I think my error is the braces. If someone could help me find my error without 'doing it for me'.

This current code is displaying 'term' whenever the user inputs the 5 digits.

Re: trouble with while statements...what am i missing?

Do you know the difference between = and ==?

Not sure what this is trying to accomplish?
if (pin >= 10000 && pin <= 76086 || pin >= 76088 && pin <= 99999)
Seems like that could be simplified. You may want to use parens to group your conditions too.

Your while loop will be executed only one time at most, since you are breaking out of it under both conditions of the if statement. Breaking out of loops is also considered to be sloppy coding because it makes the code harder to understand.

Code:

if (pin = 76087)

Code:

if (letter = B)

Code:

else if (letter = C)

Code:

if (letter = H)

You keep using the assignment operator = instead of the comparison operator == which is why your code is not working properly. Now I would agree that allowing assignments inside of an if statement is probably one of the dumbest things ever put into a programming language, but it is something we have to live with unless they ever change the language to disallow it.

Also, unless Q, B, C, and H are defined as chars and set to appropriate values, your code will not work properly either (or even compile). Character constants must be enclosed in single quotes.

Re: trouble with while statements...what am i missing?

that makes sense. Can I also mix while statements with for statements? Im doing a number classifying project now that is requiring me to display:
1. A count of the number of integers entered
2. The sum of the integers
3. The average of the integers
4. The number of odd integers
5. The number of even integers
6. The number of zeros.

I have the number of integers and average done, but when I try to do the evens ( that's as far as ive gotten) it always displays there's zero evens.

Re: trouble with while statements...what am i missing?

well, i think i found the conflict, but i cant figure out how to get the while statement and the for statement to co-exist. if i remove the while statement, the program does count the evens. I am required to do the SENTINEL statement, so would i leave the while statement out?