Hello, everyone. I'm currently trying to program a vending machine for a class that accepts a pin number 5 numbers long (else it'll loop till a proper pin number is entered), clears the screen, displays the options, selecting desired food item by letter, the price comes up and expects the user to input the proper amount till it's added up to the amount needed to pay (if it's over the price, it gives change accordingly). But I'm currently receiving a couple errors, and I have no idea what's wrong. Here's the code:
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 63 64 65 66 67 68 69 70
|
#include <cstdlib>
#include <iostream>
using namespace std;
double beverage = 5.00;
double candy = 2.25;
double hotdog = 7.00;
double popcorn = 6.75;
const int shutdown = 76087;
const int CUSTOMER = 1000;
int main(int pin, int snack, int tender, int counter, double cost)
do
{
do
{
pin = 0;
system("cls");
cout << "Welcome to Movie Food";
cout << "\nEnter your 5-digit pin code: ";
cin >> pin;
cin.clear(); cin.ignore(10, '\n');
}
while(pin < 10000 || pin > 99999);
if(pin == shutdown){break;}
do
{
snack = '\n';
system("cls");
cout << "Select a Snack\n"
<< "B - Beverage $5.00\n"
<< "C - Candy $2.25\n"
<< "H - Hot Dog $7.00\n"
<< "P - Popcorn $6.75\n"
<< "Q - Quit" << endl;
cin >> snack;
snack = toupper(snack);
}
while(snack != 'B' && snack != 'C' && snack != 'H' && snack != 'P' && snack != 'Q');
if(snack == 'Q'){continue;}
counter++;
cout << "\nYou selected";
switch(snack)
{
case 'B': cout << "Beverage" << endl; cost = beverage; break;
case 'C': cout << "Candy" << endl; cost = candy; break;
case 'H': cout << "Hot Dog" << endl; cost = hotdog; break;
case 'p': cout << "Popcorn" << endl; cost = popcorn; break;
}
do
{
cout << "Deposit" << cost << "\nEnter amount tendered ";
cin >> tender;
cin.clear(); cin.ignore(10, '\n');
cost = cost - tender;
}
while(cost > 0);
cost = abs(cost);
if(cost > 0);
{cout << "Change returned: " << cost << endl;}
system("PAUSE");
{
while(counter != CUSTOMER);
cout << endl;
cout << "This unit is shutting down to replenish its resources" << endl << endl;
system("PAUSE");
return 0;
}
}
|
I apologize if it looks messy or anything, but I'm still kinda a beginner. The errors in question are:
"expected init-decarator before "do""
and
"expected `,' or `;' before "do""
both on the same line (15).
I'm not expecting someone else to do my homework or anything, but if anyone can tell me why this error happens or what I can do about it it would be much appreciated!