This discussion is now closed.
#include <iostream>
#include <string>
using namespace std;
//Money Variables
float price;
float getmoney;
float change;
//Choice Variables
int choice;
int systemchoice;
//Drink Variables
int cocacola;
int dietcocacola;
int drpepper;
int mountaindew;
//Other Variables
int run;
string password;
string getpassword;
void TurnedOn()
{
cout <<"This machine has just been switched on!" <<endl;
cout <<"Please do some basic set up..." <<endl;
cout <<"\n";
system("PAUSE");
system("cls");
while (password.size() <4){
cout <<"Please enter the system password:" <<endl;
cout <<"(Password must be at least 4 characters)" <<endl;
cin >>password;
}
cout <<"Please enter the standard price of drinks:" <<endl;
cin >>price;
system("cls");
cout <<"Please enter the current amount of stock for:" <<endl;
cout <<"Coca Cola:";
cin >>cocacola;
system("cls");
cout <<"Please enter the current amount of stock for:" <<endl;
cout <<"Diet Coca Cola:";
cin >>dietcocacola;
system("cls");
cout <<"Please enter the current amount of stock for:" <<endl;
cout <<"Dr Pepper:";
cin >>drpepper;
system("cls");
cout <<"Please enter the current amount of stock for:" <<endl;
cout <<"Mountain Dew:";
cin >>mountaindew;
system("cls");
}
void VendCoke()
{
cout <<"Please insert $" <<price <<endl;;
cin >>getmoney;
change = (getmoney - price);
cocacola = (cocacola - 1);
cout << "\nYour change is: $" <<change <<endl;
system("pause");
system("cls");
}
void VendDietCoke()
{
cout <<"Please insert $" <<price <<endl;
cin >>getmoney;
change = (getmoney - price);
dietcocacola = (dietcocacola - 1);
cout << "\nYour change is: $" <<change <<endl;
system("pause");
system("cls");
}
void VendDrPepper()
{
cout <<"Please insert $" <<price <<endl;
cin >>getmoney;
change = (getmoney - price);
drpepper = (drpepper - 1);
cout << "\nYour change is: $" <<change <<endl;
system("pause");
system("cls");
}
void VendMountainDew()
{
cout <<"Please insert $" <<price <<endl;;
cin >>getmoney;
change = (getmoney - price);
mountaindew = (mountaindew - 1);
cout << "\nYour change is: $" <<change <<endl;
system("pause");
system("cls");
}
void SystemMenu()
{
system("cls");
cout <<"*****************************************" <<endl;
cout <<"*****************************************" <<endl;
cout <<"** System Menu **" <<endl;
cout <<"** **" <<endl;
cout <<"**1. Check Stock Levels **" <<endl;
cout <<"**2. Refill Stock **" <<endl;
cout <<"**3. Change Prices **" <<endl;
cout <<"**4. Set Machine Out Of Order **" <<endl;
cout <<"**5. Change System Password **" <<endl;
cout <<"*****************************************" <<endl;
cout <<"*****************************************" <<endl;
cin >>systemchoice;
if (systemchoice == 1){
system("cls");
cout <<"*****************************************" <<endl;
cout <<"*****************************************" <<endl;
cout <<"** Stock Levels **" <<endl;
cout <<"** **" <<endl;
cout <<"**1. Coca Cola: " <<cocacola <<" **" <<endl;
cout <<"**2. Diet Coca Cola: " <<dietcocacola <<" **" <<endl;
cout <<"**3. Dr Pepper: " <<drpepper <<" **" <<endl;
cout <<"**4. Mountain Dew: " <<mountaindew <<" **" <<endl;
cout <<"*****************************************" <<endl;
cout <<"*****************************************" <<endl;
cout <<"\n";
system("PAUSE");
}
if (systemchoice == 2){
cout <<"Please enter the current amount of stock for: Coca Cola" <<endl;
cin >>cocacola;
system("cls");
cout <<"Please enter the current amount of stock for: Diet Coca Cola" <<endl;
cin >>dietcocacola;
system("cls");
cout <<"Please enter the current amount of stock for: Dr Pepper" <<endl;
cin >>drpepper;
system("cls");
cout <<"Please enter the current amount of stock for: Mountain Dew" <<endl;
cin >>mountaindew;
system("cls");
}
if (systemchoice == 3){
cout <<"Please enter the new drinks price:" <<endl;
cin >>price;
system("cls");
}
if (systemchoice == 4){
run=0;
}
if (systemchoice == 5){
system("cls");
cout <<"Please enter the new system password:" <<endl;
cin >>password;
while (password.size() <4){
cout <<"Please enter the system password:" <<endl;
cout <<"(Password must be at least 4 characters)" <<endl;
cin >>password;
}
}
}
void MainMenu()
{
system("cls");
cout <<"*****************************************" <<endl;
cout <<"*****************************************" <<endl;
cout <<"**Choose an option by entering a number**" <<endl;
cout <<"** All drinks are currently $" <<price <<" **" <<endl;
cout <<"** **" <<endl;
cout <<"**1. Coca Cola **" <<endl;
cout <<"**2. Diet Coca Cola **" <<endl;
cout <<"**3. Dr Pepper **" <<endl;
cout <<"**4. Mountain Dew **" <<endl;
cout <<"** **" <<endl;
cout <<"**0. System Menu **" <<endl;
cout <<"*****************************************" <<endl;
cout <<"*****************************************" <<endl;
cin >> choice;
if (choice == 1) {
VendCoke();
}
if (choice == 2) {
VendDietCoke();
}
if (choice == 3) {
VendDrPepper();
}
if (choice == 4) {
VendMountainDew();
}
if (choice == 0) {
cout <<"Please enter the system password:" <<endl;
cin >>getpassword;
if (getpassword == password){
SystemMenu();
getpassword == "";
}
}
}
int main()
{
run = 1;
TurnedOn();
while(run != 0)
{
MainMenu();
}
system("cls");
cout <<"This machine is out of order. Sorry!" <<endl;
cout <<"\n" <<endl;
cout <<"\n" <<endl;
system("PAUSE");
return 0;
}
std::cin.ignore(std::cin.rdbuf()->in_avail());
std::cin.get();
#include <iostream>
#include <string>
class Vendable
{
public:
//Constructor
Vendable( unsigned int stock, std::string name )
{
// Normally I'd use initialisers here, but I'm trying to keep it
// simple ( See http://www.devx.com/tips/Tip/33146 )
stock_ = stock;
name_ = name;
}
//Destructor
~Vendable()
{
}
unsigned int getStock() const
{
return stock_;
}
std::string getName() const
{
return name_;
}
// If this returns false then cannot vend!
bool vend()
{
if ( stock_ )
{
--stock_;
return true;
}
// Out of stock!
return false;
}
private:
// Data Members
unsigned int stock_;
std::string name_;
};
void stockLevels( Vendable** vendables, unsigned int num_vendables )
{
std::cout << "Stock Levels:" << std::endl;
for ( unsigned int i = 0; i < num_vendables; ++i )
{
std::cout << vendables[ i ]->getName() << " : " << vendables[ i ]->getStock() << std::endl;
}
std::cout << std::endl;
}
void buy( Vendable* v )
{
if ( v->vend() )
{
std::cout << "Vended a " << v->getName() << std::endl;
}
else
{
std::cout << "COULD NOT VEND! OUT OF STOCK OF " << v->getName() << std::endl;
}
std::cout << std::endl;
}
int main()
{
const unsigned int starting_stock = 10;
const unsigned int num_vendables = 4;
Vendable* vendables[ num_vendables ];
vendables[ 0 ] = new Vendable( starting_stock, "Coca Cola" );
vendables[ 1 ] = new Vendable( starting_stock, "Diet Coke" );
vendables[ 2 ] = new Vendable( starting_stock, "Dr Pepper" );
vendables[ 3 ] = new Vendable( starting_stock, "Mountain Dew" );
stockLevels( vendables, num_vendables );
buy( vendables[ 0 ] );
buy( vendables[ 1 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
buy( vendables[ 2 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
buy( vendables[ 3 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
buy( vendables[ 3 ] );
buy( vendables[ 3 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
buy( vendables[ 0 ] );
stockLevels( vendables, num_vendables );
delete vendables[ 0 ];
delete vendables[ 1 ];
delete vendables[ 2 ];
delete vendables[ 3 ];
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?