help

hello i need help. why when i press "y" it does restart but it doesent let me choose how many numbers i want to use. why?

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
198
#include <iostream>

using namespace std;

class setup{
    public:
           
    void title(){
         
    system("TITLE calculator");
    system("color 2");
    cout << "hello!!!, IM A CALCULATOR... lets get started" << endl << endl;
         }
};
    


int main()
{
    setup setup1;
    setup1.title();
    
    int howmany;
    double a;
    double b;
    double c;
    double d;
    double e;
    char cchar;
    char cagain;
    
    cout << "please enter the amount of numbers you want to use: ";
    cin >> howmany;
    
    switch (howmany){
           case 1:
                cout << "invalid number" << endl;
                break;
           case 2:
                do{
    
    cout << "please enter the first number you want to use" << endl;
    cin >> a;
    cout << "please enter the operation you would like to use" << endl;
    cin >> cchar;
    cout << "please enter the second number you would like to use" << endl;
    cin >> b;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << a << " + " << b << " = "
                << (a + b) << endl;
                break;
           case '-':
                cout << "the answer is: " << a << " - " << b << " = "
                << (a - b) << endl;
                break;
           case '*':
                cout << "the answer is: " << a << " * " << b << " = "
                << (a * b) << endl;
                break;
           case '/':
                cout << "the answer is: " << a << " / " << b << " = "
                << (a / b) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           }while (cagain == 'y' || cagain == 'Y');
           break;
           
           case 3:
                do{
    cout << "please enter the operation you would like to use" << endl;
    cin >> cchar;
    cout << "please enter the first number you would like to use" << endl;
    cin >> a;
    cout << "please enter the second number you would like to use" << endl;
    cin >> b;
    cout << "please enter the third number you would like to use" << endl;
    cin >> c;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << a << " + " << b << "+" << c << " = "
                << (a + b + c) << endl;
                break;
           case '-':
                cout << "the answer is: " << a << " - " << b << "-" << c << " = "
                << (a - b - c) << endl;
                break;
           case '*':
                cout << "the answer is: " << a << " * " << b << " * " << c << " = "
                << (a * b * c) << endl;
                break;
           case '/':
                cout << "the answer is: " << a << " / " << b << " / " << c << " = "
                << (a / b / c) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           }while (cagain == 'y' || cagain == 'Y');
           case 4:
                do{
    cout << "please enter the operation you would like to use" << endl;
    cin >> cchar;
    cout << "please enter the first number you would like to use" << endl;
    cin >> a;
    cout << "please enter the second number you would like to use" << endl;
    cin >> b;
    cout << "please enter the third number you would like to use" << endl;
    cin >> c;
    cout << "please enter the forth number you would like to use" << endl;
    cin >> d;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << a << " + " << b << "+" << c << "+" << d << " = " 
                << (a + b + c + d) << endl;
                break;
           case '-':
                cout << "the answer is: " << a << " - " << b << "-" << c << "-" << d << " = "
                << (a - b - c - d) << endl;
                break;
           case '*':
                cout << "the answer is: " << a << " * " << b << " * " << c << " * " << d << " = "
                << (a * b * c * d) << endl;
                break;
           case '/':
                cout << "the answer is: " << a << " / " << b << " / " << c << " / " << d << " = "
                << (a / b / c / d) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           }while (cagain == 'y' || cagain == 'Y');
           case 5:
                do{
    cout << "please enter the operation you would like to use" << endl;
    cin >> cchar;
    cout << "please enter the first number you would like to use" << endl;
    cin >> a;
    cout << "please enter the second number you would like to use" << endl;
    cin >> b;
    cout << "please enter the third number you would like to use" << endl;
    cin >> c;
    cout << "please enter the forth number you would like to use" << endl;
    cin >> d;
    cout << "please enter the fifth number you would like to use" << endl;
    cin >> e;
    
    switch (cchar){
           
           case '+':
                cout << "the answer is: " << a << " + " << b << "+" << c << " + " << d << " + " << e << " = "
                << (a + b + c + d + e) << endl;
                break;
           case '-':
                cout << "the answer is: " << a << " - " << b << "-" << c << " - " << d << " - " << e << " = "
                << (a - b - c - d - e) << endl;
                break;
           case '*':
                cout << "the answer is: " << a << " * " << b << " * " << c << " * " << d << " * " << e << " = "
                << (a * b * c * d * e) << endl;
                break;
           case '/':
                cout << "the answer is: " << a << " / " << b << " / " << c << " / " << d << " / " << e << " = "
                << (a / b / c / d / e) << endl;
                break;
           default:
                cout << "you cant use that operation";
                break;
                }
           default:
                   cout << "invlaid number.you can only use up to 5" << endl;
           
                cout << "would you like to start again (y or n)";
           cin >> cagain;
           
           }while (cagain == 'y' || cagain == 'Y');
           }
           
    system("pause");
    return 0;
}
Using correct indenting will help you debug your programs in the future. It is not a request, it is a must as tougher programs will get MUCH more difficult if your code remains messy.

At line 193, when the condition is true, it will return you to the "do" at line 151. It will NOT return you to the top of the main

At line 32, you ask how many numbers to use. This is NOT in a loop and so once you get it the first time, you will never see it again. You need to put it in a loop for it to come up again.

Use proper indenting and you'll see exactly where each "While" bring you back and exactley what is in each loop/switch.
ok so where do i put the do i tried a couple ways but none of them worked
?
can you guys please help me
I just spent 20 minutes formatting your code to correct the indenting. Otherwise it is illegible. That is why no one has responded to you.

This is what you need to do:
1. Delete ALL lines with do{
2. Delete ALL lines with }while (cagain == 'y' || cagain == 'Y');
3. Place }while (cagain == 'y' || cagain == 'Y'); immediately before your system("pause")
4. Place a do{ immediately before your first cout <<

Other things you missed:
5. break at the end of cases 3, 4, and 5 of switch (howmany){.


Your formatted code:
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 <iostream>

using namespace std;

class setup{
    public:

    void title(){
        system("TITLE calculator");
        system("color 2");
        cout << "hello!!!, IM A CALCULATOR... lets get started" << endl << endl;
    }
};
    


int main()
{
    setup setup1;
    setup1.title();
    
    int howmany;
    double a;
    double b;
    double c;
    double d;
    double e;
    char cchar;
    char cagain;
    
    cout << "please enter the amount of numbers you want to use: ";
    cin >> howmany;
    
    switch (howmany){
    case 1:
        cout << "invalid number" << endl;
        break;
    case 2:
        do{

            cout << "please enter the first number you want to use" << endl;
            cin >> a;
            cout << "please enter the operation you would like to use" << endl;
            cin >> cchar;
            cout << "please enter the second number you would like to use" << endl;
            cin >> b;

            switch (cchar){
            
            case '+':
                cout << "the answer is: " << a << " + " << b << " = "
                << (a + b) << endl;
                break;
            case '-':
                cout << "the answer is: " << a << " - " << b << " = "
                << (a - b) << endl;
                break;
            case '*':
                cout << "the answer is: " << a << " * " << b << " = "
                << (a * b) << endl;
                break;
            case '/':
                cout << "the answer is: " << a << " / " << b << " = "
                << (a / b) << endl;
                break;
            default:
                cout << "you cant use that operation";
                break;
            }
            cout << "would you like to start again (y or n)";
            cin >> cagain;
        }while (cagain == 'y' || cagain == 'Y');
        break;
    
    case 3:
        do{
            cout << "please enter the operation you would like to use" << endl;
            cin >> cchar;
            cout << "please enter the first number you would like to use" << endl;
            cin >> a;
            cout << "please enter the second number you would like to use" << endl;
            cin >> b;
            cout << "please enter the third number you would like to use" << endl;
            cin >> c;

            switch (cchar){
        
            case '+':
                cout << "the answer is: " << a << " + " << b << "+" << c << " = "
                << (a + b + c) << endl;
                break;
            case '-':
                cout << "the answer is: " << a << " - " << b << "-" << c << " = "
                << (a - b - c) << endl;
                break;
            case '*':
                cout << "the answer is: " << a << " * " << b << " * " << c << " = "
                << (a * b * c) << endl;
                break;
            case '/':
                cout << "the answer is: " << a << " / " << b << " / " << c << " = "
                << (a / b / c) << endl;
                break;
            default:
                cout << "you cant use that operation";
                break;
            }
            cout << "would you like to start again (y or n)";
            cin >> cagain;
        }while (cagain == 'y' || cagain == 'Y');
    case 4:
        do{
            cout << "please enter the operation you would like to use" << endl;
            cin >> cchar;
            cout << "please enter the first number you would like to use" << endl;
            cin >> a;
            cout << "please enter the second number you would like to use" << endl;
            cin >> b;
            cout << "please enter the third number you would like to use" << endl;
            cin >> c;
            cout << "please enter the forth number you would like to use" << endl;
            cin >> d;

            switch (cchar){
        
            case '+':
                cout << "the answer is: " << a << " + " << b << "+" << c << "+" << d << " = " 
                << (a + b + c + d) << endl;
                break;
            case '-':
                cout << "the answer is: " << a << " - " << b << "-" << c << "-" << d << " = "
                << (a - b - c - d) << endl;
                break;
            case '*':
                cout << "the answer is: " << a << " * " << b << " * " << c << " * " << d << " = "
                << (a * b * c * d) << endl;
                break;
            case '/':
                cout << "the answer is: " << a << " / " << b << " / " << c << " / " << d << " = "
                << (a / b / c / d) << endl;
                break;
            default:
                cout << "you cant use that operation";
                break;
            }
            cout << "would you like to start again (y or n)";
            cin >> cagain;
        }while (cagain == 'y' || cagain == 'Y');
    case 5:
        do{
            cout << "please enter the operation you would like to use" << endl;
            cin >> cchar;
            cout << "please enter the first number you would like to use" << endl;
            cin >> a;
            cout << "please enter the second number you would like to use" << endl;
            cin >> b;
            cout << "please enter the third number you would like to use" << endl;
            cin >> c;
            cout << "please enter the forth number you would like to use" << endl;
            cin >> d;
            cout << "please enter the fifth number you would like to use" << endl;
            cin >> e;

            switch (cchar){
            
            case '+':
                cout << "the answer is: " << a << " + " << b << "+" << c << " + " << d << " + " << e << " = "
                << (a + b + c + d + e) << endl;
                break;
            case '-':
                cout << "the answer is: " << a << " - " << b << "-" << c << " - " << d << " - " << e << " = "
                << (a - b - c - d - e) << endl;
                break;
            case '*':
                cout << "the answer is: " << a << " * " << b << " * " << c << " * " << d << " * " << e << " = "
                << (a * b * c * d * e) << endl;
                break;
            case '/':
                cout << "the answer is: " << a << " / " << b << " / " << c << " / " << d << " / " << e << " = "
                << (a / b / c / d / e) << endl;
                break;
            default:
                cout << "you cant use that operation";
                break;
            }
        default:
            cout << "invlaid number.you can only use up to 5" << endl;
    
            cout << "would you like to start again (y or n)";
            cin >> cagain;
    
        }while (cagain == 'y' || cagain == 'Y');
    }
            
    system("pause");
    return 0;
}


I have to go to work now so I haven't applied the changes suggested above to your code.
Last edited on
Thx alot
Topic archived. No new replies allowed.