switch/case inside of a dowhile loop; Not seeing case variables.

I am sure I am overlooking something here.
Or there is a better way.
More specifically line 20 and 23
my IDE is complaining...

1
2
Use of undeclared variable. 


Full code here.
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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int rollDice(int num);
int ask_to_roll_dice(int sum);
int main(int argc, const char * argv[])
{
    int sum;
    bool quit = false;
    do {
        sum = ask_to_roll_dice(sum);
        cout << "The number of times the dice are rolled to " << "get the sum " << sum <<" = " << rollDice(sum) << endl;
        char input = '\0';
        cout << "Would you like to roll again? " << endl;
        cin >> input;
        switch (input) {
            case N:
                quit = true;
                break;
            case Y:
                quit = false;
                break;
            default:
                cout << "Invalid input";
        }
    } while (!quit);


    return 0;
}
int ask_to_roll_dice(int sum){

    cout << "What sum do you want to obtain by rolling the dice? ";
    cin >> sum;
    cout << endl;
    return sum; 
}
int rollDice(int num){
    int die1;
    int die2;
    int sum;
    int rollCount = 0;

    srand(time(0));
    do {
        die1 = rand() % 6 + 1;
        die2 = rand() % 6 + 1;
        sum = die1 + die2;
        rollCount++;
    } while (sum != num);
    return rollCount;
}



Thanks for you help in advance.
N and Y are undeclared variables. 'N' and 'Y' are char constants.
oh yea. thank you.
Final program. Just to follow up. For the sake of following up.

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
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int rollDice(int num);
int ask_to_roll_dice(int sum);
bool rollagain(bool quit);
void run();

int main(int argc, const char * argv[])
{
    run();
    return 0;
}

void run(){
    int sum;
    bool quit = false;
    do {
        sum = ask_to_roll_dice(sum);
        cout << "The number of times the dice are rolled to " << "get the sum " << sum <<" = " << rollDice(sum) << endl;
        quit = rollagain(quit);
    } while (!quit);
}

bool rollagain(bool quit){
    char input = '\0';
    cout << "Would you like to roll again? " << endl;
    cin >> input;
    input = toupper(input);
    switch (input) {
        case 'N':
            cout << "Goodbye!! " << endl;
            quit = true;
            break;
        case 'Y':
            quit = false;
            break;
        default:
            cout << "Invalid input";
    }
    return quit;
}
int ask_to_roll_dice(int sum){

    cout << "What sum do you want to obtain by rolling the dice? ";
    cin >> sum;
    cout << endl;
    return sum; 
}
int rollDice(int num){
    int die1;
    int die2;
    int sum;
    int rollCount = 0;

    srand(time(0));
    do {
        die1 = rand() % 6 + 1;
        die2 = rand() % 6 + 1;
        sum = die1 + die2;
        rollCount++;
    } while (sum != num);
    return rollCount;
}



Topic archived. No new replies allowed.