How to close out of command prompt through the program.

Hey I'm just messing around with c++ since I am new to programming and want to know how to close the command prompt when the user input 'N' after he/she gets done with the program.

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

using namespace std;

int randomIntGenerator();

int main()
{
    randomIntGenerator();
}

int randomIntGenerator()
{
    int max, randomInt, myInt;
    char YN;
    cout << "Please input max integer: ";
    cin >> max;
    cout << "Please enter the number you want to find: ";
    cin >> myInt;

    srand(time(0));
    randomInt = (rand() % max) + 1;
    while(randomInt!= myInt)
        cout << (randomInt = (rand() % max) + 1) << endl;
    cout << "You found your integer!!" << endl;

    if(randomInt == myInt)
        cout << "Would you like to try this again? Y/N: ";
        cin >> YN;
        if(YN == 'Y')
            randomIntGenerator();
        else
            //code to get the command prompt to close when user inputs N
}
Use return 0; to exit the function, and don't forget another return 0; at the end of int main()
Topic archived. No new replies allowed.