|
From: <LO5...@ao...> - 2001-05-25 13:16:10
|
#include <iostream.h>
#include <stdlib.h>
const char a = 61;
const int SENNTINEL= -999;
const char SKIP =' ';
void main()
{
char choice[10];
int num[10];
int quit;
int cost1;
int cost2;
int cost3;
int cost4;
int cost5;
int cost6;
int cost7;
int cost8;
int cost9;
int count =0 ;
int a= 61;
int b= 68;
int c= 48;
int cc=358;
int crp= 98;
int cmp=159;
int pies=53;
int t1=92;
int t2=127;
cout << SKIP << "* * ******** The Bakery ************ * *" ;
cout << endl;
cout << endl;
cout << SKIP <<" Item code Item Price " ;
cout << SKIP;
cout << endl;
cout << endl;
cout << SKIP <<" a Fresh Bread White 61p " ;
cout << endl;
cout << SKIP <<" b Fresh Bread brown 68p " ;
cout << endl;
cout << SKIP <<" c danish pastries 48p " ;
cout << endl;
cout << SKIP <<" d celabration cake 358p " ;
cout << endl;
cout << SKIP <<" e cookies regular pack 98p " ;
cout << endl;
cout << SKIP <<" f cookies maxi pack 159p " ;
cout << endl;
cout << SKIP <<" g pies 53p " ;
cout << endl;
cout << SKIP <<" h sandwiches type 1 92p " ;
cout << endl;
cout << SKIP <<" i sandwiches type 2 127p " ;
cout << endl;
cout << endl;
cout << SKIP <<"******************************************************" ;
cout << endl;
count = 0 ;
while (quit != SENNTINEL)
{
cout << "please select an item" <<endl;
cin >> choice[10];
cout << "please select quantity press"<<endl;
cin >> num[10];
count= count + 1;
cout<< count;
if (choice [1]=a)
{
cost1= a*num[1];
}
if (choice [1]=b)
{
cost1= b*num[1];
if (choice [1]=c)
{
cost1= c*num[1];
}
if (choice [1]=d)
{
cost1= d*num[1];
}
if (choice [1]=e)
{
cost1= e*num[1];
if (choice [1]=f)
{
cost1= f*num[1];
}
if (choice [1]=g)
{
cost1= g*num[1];
}
if (choice [1]=h)
{
cost1= h*num[1];
if (choice [1]=i)
{
cost1= i*num[1];
if (choice [1]=i)
{
cost1= i*num[1];
if (choice [2]=a)
{
cost2= a*num[2];
}
if (choice [2]=b)
{
cost2= b*num[2];
if (choice [2]=c)
{
cost2= c*num[2];
}
if (choice [2]=d)
{
cost2= d*num[2];
}
if (choice [2]=e)
{
cost2= e*num[2];
if (choice [2]=f)
{
cost2= f*num[2];
}
if (choice [2]=g)
{
cost2= g*num[2];
}
if (choice [2]=h)
{
cost2= h*num[2];
if (choice [2]=i)
{
cost2= i*num[2];
if (choice [2]=i)
{
cost2= i*num[2];
if (choice [3]=a)
{
cost2= a*num[3];
}
if (choice [3]=b)
{
cost2= b*num[3];
if (choice [3]=c)
{
cost2= c*num[3];
}
if (choice [3]=d)
{
cost2= d*num[3];
}
if (choice [3]=e)
{
cost2= e*num[3];
if (choice [3]=f)
{
cost2= f*num[3];
}
if (choice [3]=g)
{
cost2= g*num[3];
}
if (choice [3]=h)
{
cost2= h*num[3];
if (choice [3]=i)
{
cost2= i*num[3];
if (choice [3]=i)
{
cost2= i*num[3];
cout << "press -999 to quit or 111 to continue"<<endl;
cin >> quit;
}
cost1= choice[1] * num[1];
cost2= choice[2] * num[2];
cost3= choice[3] * num[3];
cost3= choice[4] * num[4];
cost4= choice[5] * num[5];
cost5= choice[6] * num[6];
cost6= choice[7] * num[7];
cost7= choice[8] * num[8];
cost9= choice[9] * num[9];
{
cout << SKIP << "* * ******** The Bakery ************ * *??????????
CUSTOMER INVOICE ??????????? " ;
cout << endl;
cout << endl;
cout << SKIP <<" Item Item Price Quantity
Price2 Choice Code " ;
cout << SKIP <<" Code
";
cout << endl;
cout << endl;
cout << SKIP <<" a Fresh Bread White 61p" <<" "<<num[1]<<" "
<<cost1<<" "<<choice[1];
cout << endl;
cout << SKIP <<" b Fresh Bread brown 68p" <<" "<<num[2]<<" "
<<cost2<<" "<<choice[2];
cout << endl;
cout << SKIP <<" c danish pastries 48p" <<" "<<num[3]<<" "
<<cost3<<" "<<choice[3];
cout << endl;
cout << SKIP <<" d celabration cake 358p" <<" "<<num[4]<<" "
<<cost4<<" "<<choice[4];
cout << endl;
cout << SKIP <<" e cookies regular pack 98p" <<" "<<num[5]<<" "
<<cost5<<" "<<choice[5];
cout << endl;
cout << SKIP <<" f cookies maxi pack 159p" <<" "<<num[6]<<" "
<<cost6<<" "<<choice[6];
cout << endl;
cout << SKIP <<" g pies 53p" <<" "<<num[7]<<" "
<<cost7<<" "<<choice[7];
cout << endl;
cout << SKIP <<" h sandwiches type 1 92p" <<" "<<num[8]<<" "
<<cost8<<" "<<choice[8];
cout << endl;
cout << SKIP <<" i sandwiches type 2 127p" <<" "<<num[9]<<" "
<<cost9<<" "<<choice[9];
cout << endl;
cout << endl;
cout << SKIP <<"******************************************************" ;
cout << endl;
}
system("PAUSE");
}
HELLO USERS, COULD ANY SMART PROGRAMMERS HELP ME WITH A PROBLEM, IT IS AS
FOLLOWS. I HAVE AN ARRAY CALLED CHOICE, AN ARRAY CALLED NUM AND A MENU WITH
ITEMS A TO I,
THE USER SELECTS AN ITEM(CHOICE) AND THEN A QUANTITY(NUM)
AS YOU CAN SEE FROM MY CODE ABOVE CALCULATING AN INVOICE FOR THIS CUSTOMER
IS TEDIUOS AND INEFFICIENT.
IS THERE ANOTHERWAY I COULD ATTEMPT THIS WITHOUT USING THIE METHOD BELOW
if (choice [1]=a)
{
cost1= a*num[1];
}
if (choice [1]=b)
{
cost1= b*num[1];
if (choice [1]=c)
{
cost1= c*num[1];
}
if (choice [1]=d)
{
cost1= d*num[1];
}
if (choice [1]=e)
{
cost1= e*num[1];
if (choice [1]=f)
{
cost1= f*num[1];
}
if (choice [1]=g)
{
cost1= g*num[1];
}
if (choice [1]=h)
{
cost1= h*num[1];
if (choice [1]=i)
{
cost1= i*num[1];
if (choice [1]=i)
{
cost1= i*num[1];
DO YOU SEE WHAT I MEAN I NEED A CALCULATION FOR EACH COMPONENT FOR THE ARRAY
WHICH MATCHES EACH POSSIBLE SELECTION. THIS MEANS I NEED TO WRITE ANOTHER 9
LISTS OF IF STATEMENTS AS ABOVE.
ALSO I WOULD LIKE GUIDANCE ON HOW I CAN ASK THE USER FOR AN ITEM AND THEN A
QUANTITY, RATHER THAN ASK FOR ALL ITEMS AND THEN ALL QUANTITIES TO MATCH THE
ITEMS.
PS GISAN IF YOU ARE READING THIS THANKS AGAIN FOR POINTING ME IN THE RIGHT
DIRECTION (ARRAYS).
|