Vending Machine program with loops.

Hi, I am having issues with simulating a vending machine that asks for nickels, dimes, quarters and dollars bills. First of all, the program is not calculating the total (though it was before) so it doesn't run through all the conditions. If you could help me with the loop and formula I would appreciate it.


#include <iostream>
using namespace std;

int main()
{



do{
int nickel=0;
int dime=0;
int quarter=0;
int dollar=0;
int total=0;

cout << "Insert a coin or dollar\n";
cout << "How many nickels?\n";
cin >> nickel;
cout <<total;
cout << "How many dimes?\n";
cin >> dime;
cout <<total;
cout << "How many quarters?\n";
cin >> quarter;
cout <<total;
cout << "How many dollars?\n";
cin >> dollar;
cout << "Your total is\n";
total = (nickel * 5) + (dime * 10) + (quarter *25) + (dollar*100);

cout <<total<<endl;
}while (total < 350);

if(total==350){
cout<<"Here is your candy\n";
}
else{
int change=total-350;
cout<<"Here is your change\n";
}


return 0;

}
Last edited on
What does the program print and what do you expect to be printed instead? Always provide this information (together with the input you gave the program) for future questions.
It only allows the the input of the number of coins but returns 0 for each coin total.
Try moving the variable definitions and initializations of the nickel, dime, etc. out of the do while loop. You are setting them back to zero with each interation.
Topic archived. No new replies allowed.