Making the program repeat the menu

How do I get the menu to repeat immediately after the user has input their choice? When I run it, it gives the output correct the first time, but then is blank, once you type another key it then shows the menu again. I just want it to show the menu when it also shows the answer to the input.
And also how to make the program end with the user having to press 'Enter'?

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


int main()
{
	ifstream randomFile;

	int num = 0;
	int numbers = 0;
	int max = 0;
	int min = 0;
	int counter = 0;
	double sum = 0.0;
	double average = 0.0;
	char choice;

	randomFile.open("random.txt");
	if (randomFile.fail())
	{
		cout << "File failed to open. \n";
		exit(1);
	}
	while (randomFile>>num)
	{
		if (num > max)
			max = num;
		if (num < min)
			min = num;

		sum = sum + num;
		counter++;
	}
	average = sum / counter;
	 do
	 {

		 cout << "Make a selction from the list: \n";
		 cout << "A.	Get the largest value \n";
		 cout << "B.	Get the smallest value \n";
		 cout << "C.	Get the sum of the values \n";
		 cout << "D.	Get the average \n";
		 cout << "E.	Get the number of value \n";
		 cout << "F.	End this program \n";
		 cout << "\n";
		 cout << "Enter your choice -->	";
		 cin >> choice;


		 if (choice == 'A' || choice == 'a')
			 cout << "The largest value is -->" << max << endl;
		 else if (choice == 'B' || choice == 'b')
			 cout << "The smallest value is -->" << min << endl;
		 else if (choice == 'C' || choice == 'c')
			 cout << "The sum of all the values is -->" << sum << endl;
		 else if (choice == 'D' || choice == 'd')
			 cout << "The average of all the numbers is -->" << average << endl;
		 else if (choice == 'E' || choice == 'e')
			 cout << "The number of values entered is -->" << numbers++ << endl;
		 else if (choice == 'F' || choice == 'f')
			 cout << "Program ending" << endl;
		 else
			 cout << "please enter a valid choice: ";
			 cin >> choice;

	 } 
	 while (choice == 'A' || choice == 'a' || choice == 'B' || choice == 'b' || choice == 'C' || choice == 'c' || choice == 'D' || choice == 'd' || choice == 'E' || choice == 'e' || choice == 'F' || choice == 'f');

	return 0;
}
		
At line 64, that else needs to have braces. What's happening is if there's no braces it only includes the first line of code in that else-block. The second line and from there on are all going to still be executed regardless if that else-block gets executed.

It should look like this:
1
2
3
4
5
else
{
        std::cout << "Please enter a valid choice: ";
        std::cin >> choice;
}
Topic archived. No new replies allowed.