Problem with my program involving multiple if statements

Hello im new to c++ and have a problem with the program im building. Im making a program to estimate the cost of paint and wallpaper for a decorater.I have been using multiple if statements for decision making and one of them isnt working. I can enter in the customer name, and select wallpaper and enter in the details for that. But when I try to enter paint it wont let me enter in the details for it, instead it just displays the wallpaper details. How can I change it so that when i select the paint type it displays the paint menu

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    // declare variables
    char customer[40];
    char selection;
    char paint;
    int wallpaper;
            
    
    cout << "Enter Customer name"<<endl; 
    
    cin >> customer;     

    cout <<"Paint or Wallpaper? enter p or w ";
    
    cin >> selection;
    
    if (selection == 'W' || selection == 'w' ) 
    {
    cout <<"Number of rolls of wallpaper? ";
}
     if (selection == 'P' || selection == 'p' ) 
    {
    cout <<"emulsion paint or gloss paint? ";
   }

 cin >> wallpaper;
    
    switch (wallpaper)    
    {
       case 1 : cout <<  "1 roll of wallpaper costs £5.00"; break;
       case 2 : cout <<  "2 rolls of wallpaper costs £10.00"; break;
       case 3 : cout <<  "3 rolls of wallpaper costs £15.00"; break;
       case 4 : cout <<  "4 roll of wallpaper costs £20.00"; break;
       case 5 : cout <<  "5 roll of wallpaper costs £25.00"; break;
    
       }

    cin >> paint;

    if (paint == 'E' || paint == 'e' ) 
    {
    cout << "number of litres of emulsion paint";
}

    else if (paint == 'G' || paint == 'g' )
{
    cout << "number of litres of gloss paint";
    
}

    system("PAUSE");
    return EXIT_SUCCESS;
}
You need to put the code of lines 32-42 inside the block of the if at line 23 ( if the user chose 'w', it will see the wallpaper stuff )
Similarly, the code on lines 44-55 should be inside the block of the line 27 if
I think this is what you were going for:
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    // declare variables
    char customer[40];
    char selection;
    char paint;
    int wallpaper;
            
    
    cout << "Enter Customer name\n"<<endl; 
    
    cin >> customer;     

    cout <<"Paint or Wallpaper? enter p or w \n";
    
    cin >> selection;
    
    if (selection == 'W' || selection == 'w' ) 
    {
    cout <<"Number of rolls of wallpaper? \n";

    cin >> wallpaper;
    
    switch (wallpaper)    
    {
       case 1 : cout <<  "1 roll of wallpaper costs £5.00\n"; break;
       case 2 : cout <<  "2 rolls of wallpaper costs £10.00\n"; break;
       case 3 : cout <<  "3 rolls of wallpaper costs £15.00\n"; break;
       case 4 : cout <<  "4 roll of wallpaper costs £20.00\n"; break;
       case 5 : cout <<  "5 roll of wallpaper costs £25.00\n"; break;
       }
}
     if (selection == 'P' || selection == 'p' ) 
    {
    cout <<"emulsion paint or gloss paint?\n";
cin >> paint;

    if (paint == 'E' || paint == 'e' ) 
    {
    cout << "number of litres of emulsion paint\n";
}

    else if (paint == 'G' || paint == 'g' )
{
    cout << "number of litres of gloss paint\n";
    
}
   }

    //system("PAUSE"); Don't get in the habit of using SYSTEM()
    return 0;
}
Yeah your solution worked, thanks for helping me.
Got another problem. Im trying to get the prgram to calculate the cost but when I run the program the answer ends up being a large minus number and not the result I want.



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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    // declare variables
    char customer[40];
    char selection;
    char paint;
    int wallpaper;
    int length;
    int width;
    int doors;
    int windows;
    int Elitres;
    int Glitres;
    int Gsubtotal;
    float Esubtotal;
    int Wsubtotal;
        
    
    cout << "Enter Customer name \n"<<endl;     
    cin >> customer; // User input
    
    cout <<"Paint or Wallpaper? enter p or w \n";
    
    cin >> selection;
    
    if (selection == 'W' || selection == 'w' ) 
    {
    cout <<"Number of rolls of wallpaper? \n";
    
       // wallpaper calcs
   cin >> wallpaper;
    
    switch (wallpaper)    
    {
       case 1 : cout <<  "1 roll of wallpaper costs £5.00 \n"; break;
       case 2 : cout <<  "2 rolls of wallpaper costs £10.00 \n"; break;
       case 3 : cout <<  "3 rolls of wallpaper costs £15.00 \n"; break;
       case 4 : cout <<  "4 rolls of wallpaper costs £20.00 \n"; break;
       case 5 : cout <<  "5 rolls of wallpaper costs £25.00 \n"; break;
    
       }
       
       if (wallpaper == 1)
       { Wsubtotal == 5 * 1;
                     }
       
       else if (wallpaper == 2)
       { Wsubtotal == 5 * 2;
                     }
       
       else if (wallpaper == 3)
       { Wsubtotal == 5 * 3;
                     }
                     
        else if (wallpaper == 4)
       { Wsubtotal == 5 * 4;
                     } 
                     
         else if (wallpaper == 5)
       { Wsubtotal == 5 * 5;
                     }          
                     
                     
       cout << "Subtotal = " <<Wsubtotal;
 
}

  if (selection == 'P' || selection == 'p' ) 
    {
    cout <<"emulsion paint or gloss paint? \n";
    
    //paint calcs
    
     cin >> paint;

    if (paint == 'E' || paint == 'e' ) 
    {
    cout << "number of litres of emulsion paint \n";
    
    cin >> Elitres;
    
    switch (Elitres)    
    {
       case 1 : cout <<  "1 litre of emulsion paint costs £3.50 \n"; break;
       case 2 : cout <<  "2 litres of emulsion paint costs £7.00 \n"; break;
       case 3 : cout <<  "3 litres of emulsion costs £10.50 \n"; break;
       case 4 : cout <<  "4 litres of emulsion costs £14.00 \n"; break;
       case 5 : cout <<  "5 litres of emulsion costs £17.50 \n"; break;
       
    
       }
       
  cout << "Enter Dimensions of Room \n"<<endl;
  cout << "Length = \n";
    
  cin >> length;
    
  cout << "Width = \n";
    
  cin >> width;
  
  if (Elitres == 1)
{ 3.5 * (length * width);
            }
            
  else if (Elitres == 2)
  {
       7 * (length * width);
   }
   
   else if (Elitres == 3)
  {
       10.5 * (length * width);
   }
   
   else if (Elitres == 4)
  {
       14 * (length * width);
   }
   
   else if (Elitres == 5)
  {
       17.5 * (length * width);
   }
   
        
cout <<  "subtotal = "    <<Esubtotal;
  
}

    else if (paint == 'G' || paint == 'g' )
{
    cout << "number of litres of gloss paint\n";
    
    cin >> Glitres;
    
    switch (Glitres)    
    {
       case 1 : cout <<  "1 litre of gloss paint costs £4.00\n"; break;
       case 2 : cout <<  "2 litres of gloss paint costs £8.00\n"; break;
       case 3 : cout <<  "3 litres of gloss paint costs £12.00\n"; break;
       case 4 : cout <<  "4 litres of gloss paint costs £16.00\n"; break;
       case 5 : cout <<  "5 litres of gloss paint costs £20.00\n"; break;
    
       }
    
  cout <<"Number of doors\n";
    
  cin >> doors;
    
  cout <<"Number of windows\n";
    
  cin >> windows;
 
}

if (Glitres == 1)
  {
  Gsubtotal == 4 * (doors * windows);
  
}

 else if (Glitres == 2)
  {
  Gsubtotal == 8 * (doors * windows);
  
}

else if (Glitres == 3)
  {
  Gsubtotal == 12 * (doors * windows);
  
}

else if (Glitres == 4)
  {
  Gsubtotal == 16 * (doors * windows);
  
}

if (Glitres == 5)
  {
  Gsubtotal == 20 * (doors * windows);
  
}

cout <<" Gloss subtotal = "<<Gsubtotal;
   }
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Last edited on
The code on lines 107-129 and 162-190 do nothing ( has no effect on the following code )
Use operator = for assignment. ( not == which is for comparison )
You are getting uninitialized values
Topic archived. No new replies allowed.