Press "Enter" to continue... How?

Write your question here.
Hi there, I would just like to ask what I'm supposed to do for user to just hit enter for the program to continue.

My program is a Menu program, and on case "4" it prints out the the inputs from choices 1-3 and after it does that it prompts user to hit enter to continue and uses a goto command to go back in menu.

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

int main(){

ofstream outFile;
outFile.open("mailing.txt"); // makes a txt file

int x; // variable for selection
string name; //houses name
string address; // houses addrerss
string city; // houses city, state, zip code

Menu: // so I could use "goto" command
cout << "\nMenu\n";
cout << "\t1>Enter Name\n";
cout << "\t2>Enter Address\n";
cout << "\t3>Enter City\n";
cout << "\t4>Print Mailing Addrress\n";
cout << "\t5>Exit\n";
cout << "Selection>";
cin >> x;
system("clear");

while(x < 1 || x > 5){ //If user inputs any number lower than 1 o higher than 5, progrram prompts error
system("clear");
cout << "Error! please enter a valid number.\n";
cout << "\nMenu\n";
cout << "\t1>Enter Name\n";
cout << "\t2>Enter Address\n";
cout << "\t3>Enter City\n";
cout << "\t4>Print Mailing Addrress\n";
cout << "\t5>Exit\n";
cout << "Selection>";
cin >> x;
system("clear");
}
// Switch statements for the menu
        switch(x){
        case 1:
        cout << "Enter your whole name: ";
        cin.ignore();
        getline (cin,name); // gets whole name
        outFile << name << endl;
        system("clear"); //clears whatver you were doing here
        goto Menu; //goes back to menu screen
        break;

        case 2:
        cout << "Enter your address: ";
        cin.ignore();
        getline (cin, address);
        outFile << address << endl;
        system("clear");
        goto Menu;
        break;

        case 3:
        cout << "Enter your city, state, and zip code: ";
        cin.ignore();
        getline (cin, city);
        outFile << city << endl;
        system("clear");
        goto Menu;
        break;

        case 4:
        cout << name << "\n" << address << "\n" << city << endl;
        cout << "\nPress Enter to Continue.....";
        // waits for user to hit "ENTER" key to continue
        system("clear")
        goto Menu;
        break;

        case 5:
        cout << "Good bye!\n";
        break;
}

outFile.close(); // closes txt file

return 0;
}


Thank you!
Last edited on
Hi, you could try using the function that Duoas described in http://www.cplusplus.com/forum/articles/7312/ (I suggest reading "The Standard Way" part).
The article was written for users who couldn't keep the console window open after program termination, but it works just as well in any other situation.

Also, a bit of restructuring to allow you to use a while loop here would definitely be preferred to your use of goto.
Last edited on
Topic archived. No new replies allowed.