breain=freid. do.while demons
Sep 23, 2015 at 8:15pm UTC
it couldn't be simpler. yet it doesn't work. there is no explanation i can come to.
edit:
choice1 = 1.80
choice2 = 2.60 ; etc.
if i put into userPayment, at prompt, the exact number it works. If i put in less, it works, if i put in just a few cents or dollars more than the amount it triggers the ""Please enter an amount that covers the cost of your selection worm.\n";
i can type in a large amount like 200.00 and it works. but say i choose choice1 for 1.80, then type in 2.25 for the userPayment, it triggers the less than (<) if statement.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
do {
cout << "Insert your payment; (Example: '3.10') : " ;
cin >> userPayment;
if (userPayment < choice1)
{
cout << "Please enter an amount that covers the cost of your selection worm.\n" ;
valid2 = false ;
cin.clear();
}
else if (userPayment < choice2)
{
cout << "Please enter an amount that covers the cost of your selection worm.\n" ;
valid2 = false ;
cin.clear();
}
else if (userPayment < choice3)
{
cout << "Please enter an amount that covers the cost of your selection worm.\n" ;
valid2 = false ;
cin.clear();
}
else if (userPayment < choice4)
{
cout << "Please enter an amount that covers the cost of your selection worm.\n" ;
valid2 = false ;
cin.clear();
}
else if (userPayment == choice1)
{
cout << "Exact payment given, no change to give sucker!\n" ;
valid2 = true ;
}
else if (userPayment == choice2)
{
cout << "Exact payment given, no change to give sucker!\n" ;
valid2 = true ;
}
else if (userPayment == choice3)
{
cout << "Exact payment given, no change to give sucker!\n" ;
valid2 = true ;
}
else if (userPayment == choice4)
{
cout << "Exact payment given, no change to give sucker!\n" ;
valid2 = true ;
}
else if (userPayment > choice1 || choice2 || choice3 || choice4)
{
cout << "Your change is $" << userCash(userPayment)
<< endl;
valid2 = true ;
}
}while (!valid2);
Last edited on Sep 23, 2015 at 8:19pm UTC
Sep 23, 2015 at 9:43pm UTC
Line 54.
1 2 3 4 5 6
else if (userPayment > choice1 || choice2 || choice3 || choice4)
{
cout << "Your change is $" << userCash(userPayment)
<< endl;
valid2 = true ;
}
You are only comparing userPayment to choice1.
Example:
Topic archived. No new replies allowed.