CODE
//program name: Vending Machine
//pregrammer name: Joe Deslauriers
#include <windows.h>
#include <iostream>
#include <process.h>
#include <iomanip>
#include <conio.h>
#include <string>
#include <stdio.h>
#include <ctype.h>
using namespace std;
void greetings (void);
void update_vending (int items[] , char x, int &i);
void thanks_for_shopping (int &i);
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void clrscr(int x, int y)
{
COORD coordScreen = { x, y };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '),
dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
void main(void)
{
int items[6] = {5, 5, 5, 5, 5, 5};
char x = '0';
int i = 0;
greetings( );
update_vending(items, x, i);
thanks_for_shopping(i);
_getch();
}
void greetings(void)
{
gotoxy(30,10);
cout << "Welcome to Vitto's!" << endl;
gotoxy(30,12);
cout << "Mangiare, Mangiare!" << endl;
}
void update_vending (int items[], char x, int &i)
{
system("cls");
gotoxy(30,8);
cout << "VITTO'S VENDETTA VENDING" << endl;
gotoxy(20,10);
cout << "ITEM #" << endl;
gotoxy(23,12);
cout << "1." << endl;
gotoxy(23,13);
cout << "2." << endl;
gotoxy(23,14);
cout << "3." << endl;
gotoxy(23,15);
cout << "4." << endl;
gotoxy(23,16);
cout << "5." << endl;
gotoxy(23,17);
cout << "6." << endl;
gotoxy(23,18);
cout << "N." << endl;
gotoxy(30,10);
cout << "ITEM NAME" << endl;
gotoxy(30,12);
cout << "Soprano Soup" << endl;
gotoxy(30,13);
cout << "Godfather Pasta" << endl;
gotoxy(30,14);
cout << "Gotti Gum" << endl;
gotoxy(30,15);
cout << "Capone Crisps"<< endl;
gotoxy(30,16);
cout << "Gambino Pie" << endl;
gotoxy(30,17);
cout << "Luciano Lunch" << endl;
gotoxy(30,18);
cout << "No More Purchases" << endl;
gotoxy(51,10);
cout << "PRICE" << endl;
gotoxy(51,12);
cout << "1.99" << endl;
gotoxy(51,13);
cout << "2.85" << endl;
gotoxy(51,14);
cout << "1.10" << endl;
gotoxy(51,15);
cout << "0.99" << endl;
gotoxy(51,16);
cout << "1.75" << endl;
gotoxy(51,17);
cout << "2.59" << endl;
gotoxy(61,10);
cout << "QTY" << endl;
gotoxy(61,12);
cout << items[0] << endl;
gotoxy(61,13);
cout << items[1] << endl;
gotoxy(61,14);
cout << items[2] << endl;
gotoxy(61,15);
cout << items[3] << endl;
gotoxy(61,16);
cout << items[4] << endl;
gotoxy(61,17);
cout << items[5] << endl;
gotoxy(20,20);
cout << "make a selection (1-6 or n)" << endl;
gotoxy(20,21);
cin >> x;
do
{
if(x == '1')
{
items[0] = items[0]-1;
i++;
if(items[0] == 0)
{ //if items[] reaches zero, it should say OUT and not allow the user to
gotoxy(61,12); // enter another value
cout << "OUT" << endl;
}
gotoxy(61,12);
cout << items[0] << endl;
gotoxy(20,21);
cin >> x;
}
if(x == '2')
{
items[1] = items[1]-1;
i++;
if(items[1] == 0)
{
gotoxy(61,13);
cout << "OUT" << endl;
}
gotoxy(61,13);
cout << items[1] << endl;
gotoxy(20,21);
cin >> x;
}
if(x == '3')
{
items[2] = items[2]-1;
i++;
if(items[2] == 0)
{
gotoxy(61,14);
cout << "OUT" << endl;
}
gotoxy(61,14);
cout << items[2] << endl;
gotoxy(20,21);
cin >> x;
}
if(x == '4')
{
items[3] = items[3]-1;
i++;
if(items[3] == 0)
{
gotoxy(61,15);
cout << "OUT" << endl;
}
gotoxy(61,15);
cout << items[3] << endl;
gotoxy(20,21);
cin >> x;
}
if(x == '5')
{
items[4] = items[4]-1;
i++;
if(items[4] == 0)
{
gotoxy(61,16);
cout << "OUT" << endl;
}
gotoxy(61,16);
cout << items[4] << endl;
gotoxy(20,21);
cin >> x;
}
if(x == '6')
{
items[5] = items[5]-1;
i++;
if(items[5] == 0)
{
gotoxy(61,17);
cout << "OUT" << endl;
}
gotoxy(61,17);
cout << items[5] << endl;
gotoxy(20,21);
cin >> x;
}
}while(x != tolower('N'));
}
void thanks_for_shopping(int &i)
{
system("cls");
gotoxy(30,10);
cout << "You have purchased " << i << " number of times" << endl;
gotoxy(30,11);
cout << "Thank you for shopping at Vitto's!" << endl;
}
k so in the function "update_vending" this is what needs to be done.
-clear the screen //works
-display the menu //works
-prompt for selection of a item //works
-updates (in the array as well as on the menu) the quantity left of that specific item
-the user should be allowed to choose as many snacks from the vending machine as they wish (one at a time) (if the quantity left of an item reaches zero, then the quantity left for that item should be displayed as “OUT”, not 0, and the buyer should not be allowed to select that item
//this is the only part i cant get
one last thing, how do i get the computer to wait a certain time before it calls the other function and clears the screen? i need this for inbetween the "greetings" and "update_vending" functions.
thanks for the help