How to make an play again function?

Mar 28, 2016 at 9:24am
How to make an play again function?

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
#include <iostream>
using namespace std;

int mainagain();

int main() {
    int total, g;
    cout << "Welcome to my minus game" << endl << ":D" << endl;
    cin >> total;
    while (true) {
        if ((total % 3) == 2) {
                total = total - 2;
                cout << "I minuses with 2." << endl;
        } else {
            total--;
            cout << "I minuses with 1." << endl;
        }
        cout <<  "New total is " << total << endl;
        if (total == 0) {
                cout << "I win!" << endl;
                break;
        }
        cout << "Write a number 1 or 2: ";
        cin >> g;
        while (g < 1 || g > 2) {
                cout << "You can only write 1 or 2!" << endl;
                cout << "You cant do that re-enter: ";
                cin >> g;
        }
        total = total - g;
        cout << "New total is: " << total << endl;
        if (total == 0) {
        cout << "You win!" << endl;
        break;
        }
    }
    system("PAUSE");
    return 0;
}
Last edited on Mar 28, 2016 at 3:20pm
Mar 28, 2016 at 10:06am
if you need my quick unprofessional way of doing it, put it in a while loop with an int that equals 0 and when the game is over, ask if they want to play again, if yes, the int will not change causing it to loop over again, but if they want to quit, have the int change to 1 or something, then the program will return 0 and exit out!
Last edited on Mar 28, 2016 at 10:06am
Mar 28, 2016 at 3:21pm
Thanks
Topic archived. No new replies allowed.