• 01-01-2002
Unregistered
Hi,

Please tell me what I am doing wrong.When I press A,B,C it just doesnt enter into switch case.why??
OUtput on the screen is "incorrct productcode entered.total is 0"

Actually,I want to find the total sales for entire week so should I put in while loop and keep counter 7 ???

#include<iostream>

using std::cout;
using std::cin;
using std::endl;
int main()
{
int ans,qty,counter;
double prdA,prdB, prdC,saleA,saleB,saleC,total;
saleA=0,saleB=0,saleC=0,total=0;
prdA=2.98;
prdB=4.50;
prdC = 9.98;
counter=0;

cout<<"enter the product A-C "<<endl;
cin>>ans;

switch(ans)
{
case 'A':
case 'a':
{
cout<<"enter qty"<<endl;
cin>>qty;
saleA=prdA*qty;
cout<<"ur sale is"<<saleA<<endl;
break;
}

case 'B':
case 'b':
{
cout<<"enter qty"<<endl;
cin>>qty;
saleB=prdB*qty;
cout<<"ur sale is"<<saleB<<endl;
break;
}
case 'C':
case 'c':
{
cout<<"enter qty"<<endl;
cin>>qty;
saleC=prdC*qty;
cout<<"ur sale is"<<saleC<<endl;;
break;
}

default:
{
cout<<"incorrect productcode entered"<<endl;
break;
}
}

total = saleA+saleB+saleC;
cout<<"total is "<<total;
return 0;
}

• 01-01-2002
Govtcheez
You declare ans as an int and then compare it to things like 'A' and 'B'... Let's ponder this.
• 01-01-2002
Unregistered
Thankx But...
Hi,
thanks for pointing me out for such a silly mistake.I converted it into char.
but my second query is now i want to find total sales for a entire week,so how to put it in while loop ?
thanks once again.
• 01-01-2002
Govtcheez
Smth like this:

int count = 0;

while(count <7)
{
do stuff
count++;
}
• 01-02-2002
sean
Actually, if you're dealing with chars, I doubt you can do it with a loop without a lot conversion to int and enums. You should just go through a bunch of times with the += operator.
• 01-02-2002
Unregistered
Thank you all for replying my post.