### whlie statement problem

On lines 47-53 the code is suppose to display "You have entry a negative, please try again" , however, when a correct positive number is enter I still get the display.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155`` ``````#include #include using namespace std; int main() { char carType; int A, B, C; char keepgoing; char condition; double miles, per_miles,upgrade; double days, per_days,new_char; double price, fees, charges,discount, new_charges; do { do { cout<<"Which car are you shopping for? (enter A, B, C)?"<>carType; }while (carType != 'A' && carType != 'B' && carType != 'C' ); cout<<"What condition? (S, O, or, P)"<>condition; if ((condition !='S') || (condition !='O') || (condition !='P')); else cout<<"Please enter the correct response"<>miles; do { cout<<"How many days?"<>days; cout<<"You enter a negative number,please try again."<>keepgoing; }while (keepgoing == 'Y' || keepgoing == 'y'); cout<<"Thank you for using this program. Goodbye."<
When the user enters in a number for ` days `, you didn't check if it was positive or negative. You cout the statement right after it, so the user could enter in just about anything, and the cout statement will execute.

You have to check ` if ` their input was negative, then display the message.

Would be easier to read if the code was formatted...

Also, you need to add the if statement, lol. It;s just `cout`s it, and doesn't actually reflect the values you entered.

Also, your while loop will only execute if the `days` variable is negative.
Last edited on
Topic archived. No new replies allowed.