Unable to figure out how to go back into switch statement

So I select a trivia option, I go through answer the questions get the total right out of total questions asked, then it takes me back to menu, but when I click on menu it won't go to switch statement, do I need to reset variables somehow, I know I need to reset the score variable, but that's a small problem compared to the loop not working. Any ideas?

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
int main()
{
    //Variable only used in Main()
    int option;
    //This loop is open until the user enters 6
    while(true)
    {
    cout << "************************************************************************\n";
    cout << "************************************************************************\n";
    cout << "*******************  Trivia Blast from the Past  ***********************\n";
    cout << "************************************************************************\n";
    cout << "************************************************************************\n";
    cout<<"\n\t1-->Geography";
    cout<<"\n\t2-->Sports";
    cout<<"\n\t3-->Entertainment";
    cout<<"\n\t4-->History";
    cout<<"\n\t5-->Random";
    cout<<"\n\t6-->Exit Game\n\n";
    cout<<"Please Enter Your Selection:";
    cin >> option;
    //Based on selection with option variable we will determine which Case needs to be selected
    switch(option)
        {
            case 1:
                while (counter <= 1)
                {
                //This creates the number randomly between 1 and and the number after %
                    cout << "\nYour Current Score Is: " << score <<"\n";
                    guess = rand() % 1 +1;
                    geography(guess);
                    ++counter;
                }
                if (score <= 0)
                {
                cout << "You are not very smart!!!!! You Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                if (score > 1)
                {
                cout << "Nice job!!!!! Your Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                break;
            case 2:
                while (counter <= 5)
                {
                //This creates the number randomly between 1 and and the number after %
                    cout << "\nYour Current Score Is: " << score <<"\n";
                    guess = rand() % 5 +1;
                    sports(guess);
                    ++counter;
                }
                if (score <= 0)
                {
                cout << "You are not very smart!!!!! You Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                if (score > 1)
                {
                cout << "Nice job!!!!! Your Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                break;
            case 3:
                while (counter <= 5)
                {
                //This creates the number randomly between 1 and and the number after %
                    cout << "\nYour Current Score Is: " << score <<"\n";
                    guess = rand() % 5 +1;
                    sports(guess);
                    ++counter;
                }
                if (score <= 0)
                {
                cout << "You are not very smart!!!!! You Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                if (score > 1)
                {
                cout << "Nice job!!!!! Your Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                break;
            case 4:
                while (counter <= 5)
                {
                //This creates the number randomly between 1 and and the number after %
                    cout << "\nYour Current Score Is: " << score <<"\n";
                    guess = rand() % 5 +1;
                    sports(guess);
                    ++counter;
                }
                if (score <= 0)
                {
                cout << "You are not very smart!!!!! You Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                if (score > 1)
                {
                cout << "Nice job!!!!! Your Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                break;
            case 5:
                while (counter <= 5)
                {
                //This creates the number randomly between 1 and and the number after %
                    cout << "\nYour Current Score Is: " << score <<"\n";
                    guess = rand() % 5 +1;
                    sports(guess);
                    ++counter;
                }
                if (score <= 0)
                {
                cout << "You are not very smart!!!!! You Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                if (score > 1)
                {
                cout << "Nice job!!!!! Your Final Score Is: " << score << ", you attempted to answer " << total << " questions.\n";
                }
                break;
            case 6:
                exit(0);
                break;
            default:
                cout<<"\nEnter correct choice";
                exit(0);
        }
    }
    system("pause");
    return(0);

}
I cleaned up this a little bit, I put the If Score under each CASE into a string function so I don't have repetitive code, but still can't figure out why I can't complete a game and once at back menu try another one.
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
#include <iostream>
#include <fstream>

int get_option()
{
    std::cout <<    "************************************************************************\n"
                    "************************************************************************\n"
                    "*******************  Trivia Blast from the Past  ***********************\n"
                    "************************************************************************\n"
                    "************************************************************************\n"
                    "\n\t1-->Geography"
                    "\n\t2-->Sports"
                    "\n\t3-->Entertainment"
                    "\n\t4-->History"
                    "\n\t5-->Random"
                    "\n\t6-->Exit Game\n\n"
                    "Please Enter Your Selection: " ;

    int option ;
    std::cin >> option ;
    return option ;
}

int main()
{
    int option ;
    //This loop is open until the user enters 6
    do
    {
        option = get_option() ;

        switch(option)
        {
            case 1 : std::cout << "the choice is: Geography\n\n" ; { /* ... */ } break ;
            case 2 : std::cout << "the choice is: Sports\n\n" ; { /* ... */ } break ;
            case 3 : std::cout << "the choice is: Entertainment\n\n" ; { /* ... */ } break ;
            case 4 : std::cout << "the choice is: History\n\n" ; { /* ... */ } break ;
            case 5 : std::cout << "the choice is: Random\n\n" ; { /* ... */ } break ;
            case 6 : std::cout << "the choice is: Exit Game\n\n" ; break ;
            default: std::cout << "\n\nEnter correct choice\n\n" ;
        }

    } while( option != 6 ) ;
}
ok, so you are saying calling the int option will basically initalize each time we call that function, so it resets, and then use the DO to gather is input and as long as its not 6, I will have to try this, see if I am understanding it correctly, thank you
This was very helpful, I did have to create some functions to reset my counters, for some reason they were calling it to not loop after going through a case, so I could loop thru once, but if I tried the same one again, it would just stay in the do, section because the counters were not reset. Thanks again.
Topic archived. No new replies allowed.