Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int size = 8;
double getdata (int d, int orderitem[8], int size);
double printcheck (int d, int orderitem[8], double order[8], int menulist[8], string menuitem [8], double price[8], int size);
int main ()
{
int menulist [8], orderitem[8];
string menuitem [8];
double order [8], price[8];
int d;
showmenu (menulist, menuitem, price, size);
getdata (d, orderitem, size);
printcheck (d, orderitem, order, menulist, menuitem, price, size);
cin.get();
return 0;
}
double getdata (int d, int orderitem[8], int size)
{
char h;
int r;
cout<<"Do you want to make a selection Y/y (Yes), N/n (No): ";
cin>>h;
for (r=0;r<8;r++)
{
switch(h)
{
case 'y':
case 'Y': cout<<endl;
cout<<"Enter item number: ";
cin>>orderitem[r];
cout<<endl;
cout<<"Select another item Y/y (Yes), N/n (No): ";
cin>>h;
break;
case 'n':
case 'N': d=r;
r=10;
break;
}
}
}
double printcheck (int d, int orderitem[8], double order[8], int menulist[8], string menuitem [8], double price[8], int size)
{
//local variables located below
int p;
//start printcheck
cout<<endl;
cout<<"Welcome to Johny's Resturant"<<endl;
cout<<d;
for (p=0;p<d;p++)
{
//listing the items and their prices
cout<<left<<setw(15)<<menuitem[orderitem[p]]<<price[orderitem[p]]<<endl;
}
}
its declared in "int main()"
its scope is to create the number of times the loop in "printcheck" needs to run
Program interaction should look like this (just an example)
Do you want to make a selection Y/y (Yes), N/n (No): y
Enter item number: 1
Select another Item Y/y (Yes), N/n (No): y
Enter item number: 4
Select another Item Y/y (Yes), N/n (No): y
Enter item number: 5
Select another Item Y/y (Yes), N/n (No): n
*--function getdata ends here... when the user selects N/n the statements in switch assign 'r' to 'd' then assign the value of 10 to r so that the loop cancels (THIS works somewhat as planned... the value of R does become greater than 8 so the loop cancels and d does get assigned the value of '3')
now whats NOT working is the value of 'd' being passed back through the main function to 'printcheck' because in the function 'printcheck' the value now becomes -1 for some reason...
(adding cout<<r<<" "<<d; at the end of getdata shows that everything there worked fine...adding cout<<d; to the beginning of printcheck shows d with a value of -1)