switch case where did i go wrong

Needs to show total price with tax of four different apple type using switch case

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  

#include <iostream>

using namespace std;

int main(){
    char appletype;
int num,num1,num2,num3,num4;

cout<<"Enter An Apple type"<<endl; 
cout<<"P= Premium ,J= Juicy ,S= Snack C= cooking"<<endl;
cin >> appletype;
switch(appletype)
{
                 case'P':
                         cout<<"enter amount of premuim apples"<<endl;
                         cin>>num;
                 case 'J':
                      cout<<"enter amount of juicy apples"<<endl;
                         cin>>num1;
                 case 'S':
                      cout<<"enter amount of snack apples"<<endl;
                         cin>>num2;
                 case'C':
                         cout<<"enter amount of cooking apples"<<endl;
                         cin>>num3;
                         }
                         cout<<"Total amount of all apples"<<endl;
                         cout<<((num*.4)+(num1*.03)+(num2*.02)+(num3*.01))*1.07<<endl;
                         system ("pause");
                         return 0;}
                         
                         
                                 
1. Uninitialized variables.
2. The switch case is evaluated only once.
3. No use of break; in the switch.
4. No default: in switch.

The 3 masks 1 and 2.
#include <iostream>

using namespace std;

int main(){
char appletype;
int num,num1,num2,num3,P,J,S,C;


cout<<"Enter An Apple type"<<endl;
cout<<"P= Premium ,J= Juicy ,S= Snack C= cooking"<<endl;
cin >> appletype;
switch(appletype)
{
case'P':
cout<<"enter amount of premuim apples"<<endl;
cin>>num;
break;
case 'J':
cout<<"enter amount of juicy apples"<<endl;
cin>>num1;
break;
case 'S':
cout<<"enter amount of snack apples"<<endl;
cin>>num2;
break;

case'C':
cout<<"enter amount of cooking apples"<<endl;
cin>>num3;
break;
}
cout<<"Total amount of all apples"<<endl;
cout<<((num*.4)+(num1*.03)+(num2*.02)+(num3*.01))*1.07<<endl;
system ("pause");
return 0;}
Topic archived. No new replies allowed.