I have go this working program. has 0 warning and 0 errors, it also does what it is supposed to do. But if i want to seperate the entire code into proper functions, i m pretty much lost there. I would like my main to be as simple as possible
Please helpoCode:#include <iostream> //allow input and output
using namespace std; //program uses cin and cout
int availableProducts(); //function declarations
int purchase();
int checkStat();
int main() //begin function main
{
char x=0; //variables declaration and initialization
int a[4]={5,5,5,5};
int b[4]={5,5,5,5};
int row=0;
int column=0;
double sales=0;
do //loop to keep making choices until you select exit
{
cout << "Vending machine simulator" << endl; //display menu
cout << "-------------------------------------------------" << endl;
cout << "1. Get munchies" << endl;
cout << "2. Check status" << endl;
cout << "3. Exit" << endl;
cout << "Please choose an option" << endl;
cin >> x;
switch (x) //allow choosing functions
{
case '1':
{
system("cls");
int availableProducts( int a[] , int b[] ); //display available products
{
cout << "Products available" << endl;
cout << "----------------------------------------------------------------------------" << endl;
cout << "Coke" << "\t" << "Sprite" << "\t" << "Water" << "\t" << "Mountain Dew" << endl;
cout << a[0] << "\t" << a[1] << "\t" << a[2] << "\t" << a[3] << endl;
cout << " " << endl;
cout << "M&Ms" << "\t" << "Reeses" << "\t" << "Twix" << "\t" << "Snickers" << endl;
cout << b[0] << "\t" << b[1] << "\t" << b[2] << "\t" << b[3] << endl;
}
int purchase( int a[] , int b[] , int row , int column ); //purchase products
{
do
{
cout << "Please choose a row" << endl;
cin >> row;
cout << "Please choose a column" << endl;
cin >> column;
if (column>4 || column<1)
cout << "That is not a valid choice" << endl; //condition for column out of range
else
switch (row) //switches between arrays
{
case 1:
{
if (a[column-1]<1)
cout << "Sorry, none left" << endl; //informs user item is out of stock, skips decrement of array
else
a[column-1]=a[column-1]--; //decrements a[?] as a function of the variable column
break;
}
case 2:
{
if (b[column-1]<1)
cout << "Sorry, none left" << endl; //informs user item is out of stock, skips decrement of array
else
b[column-1]=b[column-1]-1; //decrements b[?] as a function of the variable column
break;
}
default :
cout << "That is not a valid choice" << endl; //condition for row out of range
}
}
while(row!=1 && row!=2 && column<=4);
if (row==1 && column==4)
cout << "DO THE DEW!" << endl; //program advises you to do the dew
else if (row==2 && column==4)
cout << "Snickers really satisfies" << endl;
else
{
cout << "Thank you for choosing the vending machine simulator" << endl;
cout << "Please come again" << endl; //program is being polite
}
cout << " " << endl;
}
break;
}
case '2':
{
system("cls");
int checkStat( int a[] , int b[] , double sales); //check available products and display sales
{
sales=(((5-a[0]) + (5-a[1]) + (5-a[2]) + (5-a[3]))*1.25)+(((5-b[0]) + (5-b[1]) + (5-b[2]) + (5-b[3]))*0.75);
cout << "Total number of items sold from row 1: " << ((5-a[0]) + (5-a[1]) + (5-a[2]) + (5-a[3])) << endl;
cout << "Total number of items sold from row 2: " << ((5-b[0]) + (5-b[1]) + (5-b[2]) + (5-b[3])) << endl;
cout << " " << endl;
cout << "Total sales are: $" << sales << endl;
}
break;
}
case '3':
{
cout << "Goodbye!" << endl; //break out of loop and exit
break;
}
default:
cout << "That function is not possible" << endl;
}
system("pause"); //pause to see results
system("cls");
}
while(x!='3'); //completes loop to keep choosing
return 0; //indicate successful program execution
}