#define OP_1 "You have selected a Cola"
#define OP_2 "You have selected a Fanta"
#define OP_3 "You have selected a Tango"
#define OP_FIN "That drink is not on the list. Pick between 1-3"
//prices of drinks
nPrices = 0.25; // Coke
nPrices = 0.35; // Fanta
nPrices = 0.20; // Tango
nBalance = 2;
cout << "What drink would you like to select? (zero to stop)" << endl;
cout << "1 = Cola" << endl << "2 = Fanta" << endl << "3 = Tango" << endl;
cout << "Your current balance is " << " $ " << nBalance << endl;
cin >> drink;
if (drink > 0)
case 1: cout << OP_1 << endl << endl << (nBalance-nPrices) << endl;
case 2: cout << OP_2 << endl << endl << (nBalance-nPrices) << endl;
case 3: cout << OP_3 << endl << endl << (nBalance-nPrices) << endl;
default: cout << OP_FIN << endl;
while (drink > 0);
What is the problem? Well I am trying to deduct the nBalance from the nPrices and update the the remaining value. However it keeps outputting 2 everytime. I have managed to get the argument to work it will deduct and print the remaining value out but then selecting another drink it won't update.
The point Moschops was trying to make is that there is no place in your code where you change the value of nBalance. If you want nBalance to have a different value the next time through the loop, you need to change it. And as TheIdeasMan pointed out if you subtract a fraction (e.g. 0.25) from in int, that won't change the value of the int.