output never stops repeating [ Soda machine simulator]

after I get the output it repeats forever and never stops does anyone know why and how can I stop this.


#include <iostream>
#include <iomanip>
using namespace std;



void getChoice(char & letter);

int main()
{

char selection;
double change, money,earnings,cost3 =.75, cost2 = .80, amount = 20;
earnings += money;


cout << "Which Beverage would you like to purchase today\n";
cout << "(A) Cola \n";
cout << "(B) RootBeer\n";
cout << "(C) Lemon-Lime \n";
cout << "(D) Grape Soda\n";
cout << "(E) Cream Soda \n";
cout << "(F) Quit Purchase \n";
getChoice (selection);

switch (selection)
{
case 'A' :
case 'a' : cout << "Please enter no more than $1.00 or less than .75 Cents!: ";
cin >> money;
while( money < cost3 || money > 1)
{
cout << "Invalid! Please Re-Enter amount between .75 Cents to a $1.00: " << endl;
cin >> money;
}

while (money == 1)
{
change = money - cost3;
cout << "your change is" << change << endl;
}
while (money == cost3)
{

cout << "your purchase is complete" << endl;
};

break;


case 'B' :
case 'b' :cout << "Please enter no more than $1.00 or less than .75 Cents!: ";
cin >> money;
while( money < cost3 || money > 1)
{
cout << "Invalid! Please Re-Enter amount between .75 Cents to a $1.00: " << endl;
cin >> money;
}

while (money == 1)
{
change = money - cost3;
cout << "your change is" << change << endl;
}
while (money == cost3)
{

cout << "your purchase is complete" << endl;
}

break;


case 'C' :
case 'c' : cout << "Please enter no more than $1.00 or less than .75 Cents!: ";
cin >> money;
while( money < cost3 || money > 1)
{
cout << "Invalid! Please Re-Enter amount between .75 Cents to a $1.00: " << endl;
cin >> money;
}

while (money == 1)
{
change = money - cost3;
cout << "your change is" << change << endl;
}
while (money == cost3)
{

cout << "your purchase is complete" << endl;
}

break;

case 'D' :
case 'd' : cout << "Please enter no more than $1.00 or less than .80 Cents!: ";
cin >> money;
while( money < cost2 || money > 1)
{
cout << "Invalid! Please Re-Enter amount between .80 Cents to a $1.00: " << endl;
cin >> money;
}

while (money == 1)
{
change = money - cost3;
cout << "your change is" << change << endl;
}
while (money == cost2)
{

cout << "your purchase is complete" << endl;
}

break;
case 'E' :
case 'e' : cout << "Please enter no more than $1.00 or less than .80 Cents!: ";
cin >> money;
while( money < cost2 || money > 1)
{
cout << "Invalid! Please Re-Enter amount between .80 Cents to a $1.00: " << endl;
cin >> money;
}

while (money == 1)
{
change = money - cost3;
cout << "your change is" << change << endl;
}
while (money == cost2)
{

cout << "your purchase is complete" << endl;
}

break;

case 'F' :
case 'f' :
exit(0);
break;

}

system("PAUSE");
return 0;
}
void getChoice(char & letter )
{

cout << "Enter your choice: ";
cin >> letter;

while ( letter != 'A' && letter != 'a' &&
letter != 'B' && letter != 'b' &&
letter != 'C' && letter != 'c' &&
letter != 'D' && letter != 'd' &&
letter != 'E' && letter != 'e' &&
letter != 'F' && letter != 'f' )
{
cout << "Please enter (A)(B)(C)(D)(E): ";
cin >> letter;
}

}

[/code]
Of course it could not stop.

You ask to enter letter and then you enter loop inside which you check the letter and print warning, check the letter and print warning, check the letter...

Since you never change variable in this loop, all checks are the same. Perhaps you should have input for the letter inside the loop.

And please use code tags to format your code if you want to ask for help. It is unreadable!

P.S. Perhaps it will be good for you to have more practice with simple programs on loops etc., like from this problem solving site:

http://codeabbey.com/index/task_list/beginners-problems
Last edited on
Topic archived. No new replies allowed.