Eric
April 13th, 1999, 09:02 AM
I am trying to write a code that has 3 products called 1,2,3. Product one is worth $1 and Product 2 is
worth $2 and Product 3 is worth $3.
Now I want to be able to ask the user to Enter the day of the week.
And then Enter the Product Number . eg: 1 , 2 or 3
How many sold?
And the results should come out.
But I am having trouble with it.
Could you be kind enough to look at the code and tell me what I need to add to it so it works.
And what is missing or wrong with the one I wrote.
I am having serious problems here. I am new to programming so please explain in the simplest
way you can.
I thank you in advance.
PS: If you compile it , you will see the result i get and what it should be.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
main()
{
clrscr();
int P1=1,P2=2,P3=3,sum1=0,sum2=0,sum3=0,total=0,Pnumber=0,sold=0,tsold=0;
char day;
cout<<"To end program press crtl + z\n";
cout<<"\nEnter the Day please:\t";
cin>>day;
cout<<"\nEnter Part Number:\t";
cin>>Pnumber;
cout<<"\nEnter how many was Units sold:\t";
cin>>sold;
while(( Pnumber = getchar() ) !=EOF )
{
switch ( Pnumber )
{
case 1:
sum1 = ( P1 * sold );
total += sum1;
tsold = (sold + tsold);
break;
case 2:
sum2 = ( P2 * sold );
total += sum1;
tsold = (sold + tsold);
break;
case 3:
sum3 = ( P3 * sold );
total += sum1;
tsold = (sold + tsold);
break;
default:
cout<<"The Part Numbers are [ 1 , 2 , 3 ] only";
cout<<"\nEnter Part Number:\t";
}
}
cout<<day<<"\n";
cout<<"\n"<< "Partnumber Price Units Sold cost";
cout<<"\n\t1"<<"\t"<<"$1"<<" \t "<<tsold<<"\t\t"<<sum1;
cout<<"\n\t2"<<"\t"<<"$2"<<" \t "<<tsold<<"\t\t"<<sum2;
cout<<"\n\t3"<<"\t"<<"$3"<<" \t "<<tsold<<"\t\t"<<sum3;
cout<<"\n\t\t\t\t"<<" Total "<<total;
getch();
return 0;
}
worth $2 and Product 3 is worth $3.
Now I want to be able to ask the user to Enter the day of the week.
And then Enter the Product Number . eg: 1 , 2 or 3
How many sold?
And the results should come out.
But I am having trouble with it.
Could you be kind enough to look at the code and tell me what I need to add to it so it works.
And what is missing or wrong with the one I wrote.
I am having serious problems here. I am new to programming so please explain in the simplest
way you can.
I thank you in advance.
PS: If you compile it , you will see the result i get and what it should be.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
main()
{
clrscr();
int P1=1,P2=2,P3=3,sum1=0,sum2=0,sum3=0,total=0,Pnumber=0,sold=0,tsold=0;
char day;
cout<<"To end program press crtl + z\n";
cout<<"\nEnter the Day please:\t";
cin>>day;
cout<<"\nEnter Part Number:\t";
cin>>Pnumber;
cout<<"\nEnter how many was Units sold:\t";
cin>>sold;
while(( Pnumber = getchar() ) !=EOF )
{
switch ( Pnumber )
{
case 1:
sum1 = ( P1 * sold );
total += sum1;
tsold = (sold + tsold);
break;
case 2:
sum2 = ( P2 * sold );
total += sum1;
tsold = (sold + tsold);
break;
case 3:
sum3 = ( P3 * sold );
total += sum1;
tsold = (sold + tsold);
break;
default:
cout<<"The Part Numbers are [ 1 , 2 , 3 ] only";
cout<<"\nEnter Part Number:\t";
}
}
cout<<day<<"\n";
cout<<"\n"<< "Partnumber Price Units Sold cost";
cout<<"\n\t1"<<"\t"<<"$1"<<" \t "<<tsold<<"\t\t"<<sum1;
cout<<"\n\t2"<<"\t"<<"$2"<<" \t "<<tsold<<"\t\t"<<sum2;
cout<<"\n\t3"<<"\t"<<"$3"<<" \t "<<tsold<<"\t\t"<<sum3;
cout<<"\n\t\t\t\t"<<" Total "<<total;
getch();
return 0;
}