Can't figure out how to add an exit prompt

Alright so I've complete my program for a CS 161 Assignment, but for the life of me I can not figure out how to add an exit prompt with out it interfering with the output of the code. I do not want the answer but some hints or tips would be greatly appreciated.
Thank you in Advanced.

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
 #include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;


bool IsPrime(long n);
long power2(long n);

int  main()
{

	char reply;

	cout << "Mersenne Primes by Rudy Cortez" << endl;
	cout << endl;
	cout << "n" << setw(30) << setfill(' ') << "Mersenne Prime" << endl;
	cout << "==" << setw(29) << setfill(' ') << "=============" << endl;

	for (long i = 0; i <= 100; i++) {
		if (IsPrime(i))
			power2(i);

	}
	cout << "Press any key to exit followed by 'Enter'\n";
	cin >> reply;
	return 0;
}



	bool IsPrime(long n)
	{
		long i = 0;
		long counter = 0;

		for (i = 1; i <= n; i++)
		{
			if (n % i == 0)
			{
				counter++;
			}
		}
		if (counter == 2)

			return true;

		else

			return false;


	}

	long power2(long  n)
	{ 
		long mprime;

		mprime = (1L << n) - 1;
		if (IsPrime(mprime))
			cout << n << setw(30) << setfill(' ') << mprime << "\n";
		
		return 0;
	}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>

bool done=false;

void ExitOrNaw()
{
  std::string key;
  std::cout << "Do you want to exit? (Y|N)";
  std::cin >> key;
  if(key=="Y") done=true;
}

int main()
{
  firstOperation();
  ExitOrNaw();
  if(done==true) return 0;
  secondOperation();
  if(done==true) return 0;
  //etc.
  return 0;
}
Last edited on
Topic archived. No new replies allowed.