April 18th, 1999, 05:45 AM
I am having some trouble with this code that I am trying to complete.
I know I should be adding a loop or something somewhere but I dont
know where. Also I am very new at programming and it is my first
time using switches. But it is not working ( I think ).
Could you be kind enough to guide me in the right direction. It would
be a great help to me.
I thank you in advance.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
main()
{
clrscr();
int day,Pnumber=0,Usold=0,count1=0,count2=0,count3=0,P1=0,P2=0,P3=0;
cout<<"\nPress ctrl + z to end program.";
cout<<"\n\nThe day of the week should be in Numbers.";
cout<<"\neg: Monday = 1, Tuesday = 2 and so on.";
cout<<"\n\nEnter the Day of the Week:"; // Day of week is a number
cin>>day; // eg: Monday = 1, Tuesday = 2 and so on
cout<<"\nEnter the Part Number:";
cin>>Pnumber; // Part numbers are 1 , 2 or 3 only
cout<<"\nEnter Units Sold:";
cin>>Usold; // How many Units were sold
while (( Pnumber = getchar() ) !=EOF )
{
switch (Pnumber) //P1,P2,P3 will hold the subtotal
{ //in the end for the output
case 1:
int P1 = 0;
P1 = (Pnumber * 1);
int count1 = 0; //count1,2,3 will hold the output
count1 = (Usold + count1); //for Units sold
break;
case 2:
int P2 = 0;
P2 = (Pnumber * 2);
int count2 = 0;
count2 = (P2 + count2);
break;
case 3:
int P3 = 0;
P3 = (Pnumber * 3);
int count3 = 0;
count3 = (P3 + count3);
break;
default:
cout<<"\n\nWrong Part Number Used";
cout<<"\nPlease use only Part Numbers 1 or 2 or 3";
break;
}
}
if ( day == 1 )
cout<<"Monday";
if ( day == 2 )
cout<<"Tuesday";
if ( day == 3 )
cout<<"Wednesday";
if ( day == 4 )
cout<<"Thursday";
if ( day == 5 )
cout<<"Friday";
if ( day == 6 )
cout<<"Saturday";
if ( day == 7 )
cout<<"Sunday";
cout<<"\nPart Number Unit Price Units Sold Sub Total";
cout<<"\n1"<<"\t\t$1"<<"\t\t"<<count1<<"\t"<<"\t"<<P1;
cout<<"\n2"<<"\t\t$2"<<"\t\t"<<count2<<"\t"<<"\t"<<P2;
cout<<"\n3"<<"\t\t$3"<<"\t\t"<<count3<<"\t"<<"\t"<<P3;
getch();
return 0;
}
I know I should be adding a loop or something somewhere but I dont
know where. Also I am very new at programming and it is my first
time using switches. But it is not working ( I think ).
Could you be kind enough to guide me in the right direction. It would
be a great help to me.
I thank you in advance.
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
main()
{
clrscr();
int day,Pnumber=0,Usold=0,count1=0,count2=0,count3=0,P1=0,P2=0,P3=0;
cout<<"\nPress ctrl + z to end program.";
cout<<"\n\nThe day of the week should be in Numbers.";
cout<<"\neg: Monday = 1, Tuesday = 2 and so on.";
cout<<"\n\nEnter the Day of the Week:"; // Day of week is a number
cin>>day; // eg: Monday = 1, Tuesday = 2 and so on
cout<<"\nEnter the Part Number:";
cin>>Pnumber; // Part numbers are 1 , 2 or 3 only
cout<<"\nEnter Units Sold:";
cin>>Usold; // How many Units were sold
while (( Pnumber = getchar() ) !=EOF )
{
switch (Pnumber) //P1,P2,P3 will hold the subtotal
{ //in the end for the output
case 1:
int P1 = 0;
P1 = (Pnumber * 1);
int count1 = 0; //count1,2,3 will hold the output
count1 = (Usold + count1); //for Units sold
break;
case 2:
int P2 = 0;
P2 = (Pnumber * 2);
int count2 = 0;
count2 = (P2 + count2);
break;
case 3:
int P3 = 0;
P3 = (Pnumber * 3);
int count3 = 0;
count3 = (P3 + count3);
break;
default:
cout<<"\n\nWrong Part Number Used";
cout<<"\nPlease use only Part Numbers 1 or 2 or 3";
break;
}
}
if ( day == 1 )
cout<<"Monday";
if ( day == 2 )
cout<<"Tuesday";
if ( day == 3 )
cout<<"Wednesday";
if ( day == 4 )
cout<<"Thursday";
if ( day == 5 )
cout<<"Friday";
if ( day == 6 )
cout<<"Saturday";
if ( day == 7 )
cout<<"Sunday";
cout<<"\nPart Number Unit Price Units Sold Sub Total";
cout<<"\n1"<<"\t\t$1"<<"\t\t"<<count1<<"\t"<<"\t"<<P1;
cout<<"\n2"<<"\t\t$2"<<"\t\t"<<count2<<"\t"<<"\t"<<P2;
cout<<"\n3"<<"\t\t$3"<<"\t\t"<<count3<<"\t"<<"\t"<<P3;
getch();
return 0;
}