Heres the code for it if anyone is interested:
Code:
/*
Program Name:
Author: Mark Birchfield
Course: CSC 2134
Date Due:
Purpose:
Data Dictionary
Variable Name Data Type Use/Value
coke int holds # cokes left
sprite int holds # sprites left
pepsi int holds # pepsi left
mount_dew int holds # mountain dew left
jolt int holds # jolts left
selection_empty int is the desired soda empty?
selection_made int have we chosen already?
num_quarters int tracks # quarters for change
num_dimes int tracks # dimes for change
num_nickels int tracks # nickels for change
flag int had 75 cents been entered?
selection int desired frosty beverate
input float coin value input into machine
slot float is input is good, slot = input
change float remainder from input
total float total "good" money put in
change_count float used to figure coin #s
again char repeats the program
*/
#include <iostream>
#include <conio.h>
#include <iomanip>
using namespace std;
int main()
{
int coke=4, sprite=4, pepsi=4, mount_dew=4, jolt=4,selection_empty;
int selection_made=0;
int num_quarters=0, num_dimes=0, num_nickels=0, flag, selection;
float input=0, slot=0, change=0, total=0, change_count;
char again;
do
{
do
{
system("CLS");
cout <<setprecision(2)<<setiosflags(ios::fixed|ios::showpoint);
cout<<" Ice Cold Cola\n";
cout<<" .75 cents\n\n";
cout<<"Deposit -- dollar, quarters, dimes, or nickels:\n";
cout<<" ( 1 , .25 , .10 , .05)\n\n";
cout<<" Slot [ "<<total<<" ]\n\n\n";
cout<<"Coin Return [ "<<change<<" ]\n";
cout<<"Enter Coin [--------] ";
//-----------------------------------------------------------------
//This starts the input coin controls. Pretty self explanatory.
//-----------------------------------------------------------------
if (total>=.75)
{
flag=1;
break;
}
else
{
cin>>input;
}
if (input > .99 && input < 1.1)
{
slot = 1.0;
total += slot;
}
else if (input > .24 && input < .26)
{
slot = .25;
total += slot;
}
else if (input > .09 && input < .11)
{
slot = .10;
total += slot;
}
else if (input > .04 && input < .06)
{
slot = .05;
total += slot;
}
else if (input == -1)// This "turns off" the software and closes program.
{
return 0;
}
else
{
change += input;
input = 0;
}
}while (flag !=1);
flag=0;
//----------------------------------------------------------------------------
//
//This starts the counting process to identify the amount of change in specific
//coins.
//
//----------------------------------------------------------------------------
if (total >.75 )
{
change_count = total - .75;
if (change_count != 0)
{
while (change_count >=.25 )
{
++num_quarters;
change_count-=.25;
}
while (change_count >=.10 && change_count < .25)
{
change_count -=.10;
++num_dimes;
}
while (change_count >=.05 && change_count <.10)
{
change_count -= .05;
++num_nickels;
}
}
}
do
{
//--------------------------------------------------------------------------
// This starts the soda selection and display menu.
//
//--------------------------------------------------------------------------
do
{
cout <<"\n\n\t\tSoda selection:\n\n";
cout <<"1. Coke ";
cout <<"\t2. Sprite ";
cout <<"\t3. Pepsi ";
cout <<"\t4. Mountain Dew";
cout <<"\t5. Jolt \n\n ";
cout<<" "<<coke<<"\t\t "<<sprite<<"\t\t "<<pepsi<<"\t\t ";
cout<<mount_dew<<"\t\t "<<jolt<<"\n\n\n";
cout <<"\tEnter Your Choice:";
cin >> selection;
}while (selection <1 || selection >5);
switch (selection)
{
case 1: cout<<"\t\t\n\nYou have selected Coke.\n\n";
if (coke==0)
{
cout<<"This selection is empty.Please select another.\n";
selection_empty=1;
continue;
}
else
{
coke--;
selection_made=1;
break;
}
case 2: cout<<"\t\t\n\nYou have selected Sprite.\n\n";
if (sprite==0)
{
cout<<"This selection is empty.Please select another.\n";
selection_empty=1;
continue;
}
else
{
sprite--;
selection_made=1;
break;
}
case 3: cout<<"\t\t\n\nYou have selected Pepsi.\n\n";
if (pepsi==0)
{
cout<<"This selection is empty.Please select another.\n";
selection_empty=1;
continue;
}
else
{
pepsi--;
selection_made=1;
break;
}
case 4: cout<<"\t\t\n\nYou have selected Mountain Dew.\n\n";
if (mount_dew==0)
{
cout<<"This selection is empty.Please select another.\n";
selection_empty=1;
continue;
}
else
{
mount_dew--;
selection_made=1;
break;
}
case 5: cout<<"\t\t\n\nYou have selected Jolt Cola!!\n\n";
if (jolt==0)
{
cout<<"This selection is empty.Please select another.\n";
selection_empty=1;
continue;
}
else
{
jolt--;
selection_made=1;
break;
}
}
if (coke==0 && sprite==0 && pepsi==0 && mount_dew==0 && jolt==0)
{
cout<<"Machine is empty! Time to restock!";
break;
}
if (selection_made==1)
{
break;
}
//-----------------------------------------------------------------------
//Here is the final display of change. After this the program restarts
//depending on the input and various other items.
//-----------------------------------------------------------------------
}while (selection_empty ==1);
cout<<"\n\t\t Here's your soda!!\n";
if (num_quarters>=1 || num_dimes>=1 || num_nickels>=1)
cout<<"Your change is: ";
if (num_quarters >=1)
cout<< num_quarters<<" Quarter(s)\n";
if (num_dimes >=1)
cout<< num_dimes<<" Dime(s)\n";
if (num_nickels >=1)
cout<<num_nickels<<" Nickels(s)\n";
//------------------------------------------------zero out for a new run
change=0; total=0; num_quarters=0; num_dimes=0; num_nickels=0;
//---------------------------------------------------------------------
cout<<"\t\tHave a Nice Day!\n\n\n";
cout <<"Hit any key to continue";
cin.ignore();
cin.get(again);
}while (again);
}
Bookmarks