This discussion is now closed.
Scroll to see replies
#include <iostream>
using namespace std;
int choc;
choc = 10;
int pin;
pin = 0;
void choice ()
{
cout <<"Please enter your pin number" << endl;
cin >> pin;
while (pin != 5008)
{
cout <<"Invalid pin number, please re-enter" << endl//No semicolon
cin >> pin;
}
if (pin == 5008)
{
cout << "please refill the chocolate bars by " << choc - 10 << endl;
}
}
int main ()
{
int choice;
int cash;
cash =0;
int choc;
choc = 10;
int change1;
change1 = 0;
int x;
x = 0;
int y;
y = 0;
int change2;
change2 = 300;
cout << "Welcome to Rob's chocolate machine \n \n " << endl;
cout << "This machine only accepts \n5 pence coins \n10 pence coins\n20 pence coins\n50 pence coins\n1 pound(100 pence) coins\n2 pound(200 pence) coins"<< endl;
cout << "If you are the operater, please press 1, otherwise press any other key to continue"<< endl;
cin >> choice;
if (choice == 1)
{
choice();
}
else {
while (y=1)//Should be ==1
{
cout << "There are "<< choc << " chocolate bars remaining \n " << endl;
cout << "Chocolate bars are 65 pence \n \n" << endl;
cout << "Please enter your cash : " << endl;
cin >> cash;
while(cash < 65)
{
cout << "Please enter more cash, your current credit is : " << cash << endl;
cin >> x;
cash = cash + x;
}
if (cash >= 65)
{
change1 = cash - 65;
cout << "Thank you for your selection\n" << endl;
cout <<"Please collect your change : " << change1 << endl;
cout << "\nRemaining chocolate bars is : " << choc -1 << endl;
change2 = change2 - change1;
cout << change2<< endl;
cout << "If you would like another chocolate bar, please press 1" << endl;
choc = choc - 1;
cin >> y;
}
}
}
return 0;
}
#include <iostream>
using namespace std;
int choc =10;
int pin =0;
int change2 =300;
int change1 =0;
int refill =0;
int refill2 =0;
void choice ()// this is the function for the operator
{
cout <<"Please enter your pin number" << endl;
cin >> pin;
while (pin != 5008)
{
cout <<"Invalid pin number, please re-enter" << endl;
cin >> pin;
}
if (pin == 5008)
{
cout << "Please refill the chocolate bars by a maximum of " << 10 - choc << endl;
cin >> refill;
cout << "Thank you, there is currently " << choc + refill << " bars" << endl;
cout << "Curent change remaining is " << change2 << endl;
cout << "Now refill the change without exceeding " << 300 - change2 <<" please" << endl;
cin >> refill2;
change2 = refill2 + change2;
cout << "Current change is " << change2 << endl;
cout <<"Thank you for refilling the machine, this simulation will now exit. " << endl;
}
}
int main ()
{
int choose =0;
int cash = 0;
int x = 0;
int y = 0;
cout << "\n\n\t \t Welcome to Rob's chocolate machine \n \n" << endl;
cout << "This machine only accepts \n5 pence coins \n10 pence coins\n20 pence coins\n50 pence coins\n1 pound(100 pence) coins\n2 pound(200 pence) coins"<< endl;
cout << "If you are the operater, please press 1, \notherwise press any other key to continue"<< endl;
cin >> choose;
if (choose == 1)
{
choice();
}
else
{
while (y=1)
{
cout << "There are "<< choc << " chocolate bars remaining \n " << endl; // the main function
cout << "Chocolate bars are 65 pence \n \n" << endl;
cout << "Please enter your cash : " << endl;
cin >> cash;
while(cash < 65)
{
cout << "Please enter more cash, your current credit is : " << cash << endl;
cin >> x;
cash = cash + x;
}
if (cash >= 65)
{
change1 = cash - 65;
cout << "Thank you for your selection\n" << endl;
cout <<"Please collect your change : " << change1 << endl;
cout << "\nRemaining chocolate bars is : " << choc -1 << endl;
change2 = change2 - change1;
cout << "If you would like another chocolate bar, please press 1" << endl;
choc = choc - 1;
cin >> y;
while (y != 1)
{
choice();
}
}
}
}
return 0;
}
Last reply 1 month ago
Free website hosting providers with no strings attached?Posted 3 months ago
iDEA silver citizen badge three. Milkshake shack coding problem.Last reply 4 months ago
How do you practice programming java for beginners?Last reply 8 months ago
hows the employment market for tech work in the UK?Last reply 1 month ago
Free website hosting providers with no strings attached?Posted 3 months ago
iDEA silver citizen badge three. Milkshake shack coding problem.Last reply 4 months ago
How do you practice programming java for beginners?Last reply 8 months ago
hows the employment market for tech work in the UK?