So I've searched all over but I can't seem to find any help on how to loop menus a specific way. I know this question has been asked a million times, but I can't wrap my head around how to go about it. I want to loop the portion where the user enters their info and after it is displayed. Start from the top if the user enters in N.
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
//define max variable lengths for inputs.
#define MAX_NAME_LENGTH 50
#define MAX_EMAIL_LENGTH 100
#define MAX_DESCRIBE_LENGTH 300
int main (){
// Set variables for inputs by user using char
char userName[MAX_NAME_LENGTH];
char userEmail[MAX_EMAIL_LENGTH];
char userInfo[MAX_DESCRIBE_LENGTH];
constchar nl2[] = "\n\n"; //creates two break lines
// prompts asking for user input
cout << "Hello and welcome to VendPro Profile Builder"<< endl<< endl;
cout << "Please enter your name to begin" << endl << nl2 << endl;
cin.getline(userName,MAX_NAME_LENGTH); // will alow user to input requested info
cout << " Thank you. Now, please enter in a valid email address" << endl << nl2 << endl;
cin.getline(userEmail,MAX_EMAIL_LENGTH);
cout << "Thank you. Now, tell us about yourself? When complete please enter # to complete. " << endl <<nl2<< endl;
cin.getline(userInfo,MAX_DESCRIBE_LENGTH,'#');
cout << "Please Review information below. Is it correct? " << endl<< nl2 << endl;
cout << " Your information" << endl << endl;
cout << "========================" << endl;
cout << "Name : " << userName << endl;
cout << "Email : " << userEmail << endl;
cout << " About You :" << userInfo << endl;
cout << "Is the information Correct? Please enter "Y" for Yes and "N" for No " << endl;
}
#include <iostream>
#include <string>
#include <cmath>
usingnamespace std;
//define max variable lengths for inputs.
#define MAX_NAME_LENGTH 50
#define MAX_EMAIL_LENGTH 100
#define MAX_DESCRIBE_LENGTH 300
int main (){
// Set variables for inputs by user using char
char userName[MAX_NAME_LENGTH];
char userEmail[MAX_EMAIL_LENGTH];
char userInfo[MAX_DESCRIBE_LENGTH];
constchar nl2[] = "\n\n"; //creates two break lines
// prompts asking for user input
cout << "Hello and welcome to VendPro Profile Builder"<< endl<< endl;
string userInput = "N";
while (userInput == "N")
{
cout << "Please enter your name to begin" << endl << nl2 << endl;
cin.getline(userName,MAX_NAME_LENGTH); // will alow user to input requested info
cout << " Thank you. Now, please enter in a valid email address" << endl << nl2 << endl;
cin.getline(userEmail,MAX_EMAIL_LENGTH);
cout << "Thank you. Now, tell us about yourself? When complete please enter # to complete. " << endl <<nl2<< endl;
cin.getline(userInfo,MAX_DESCRIBE_LENGTH,'#');
cout << "Please Review information below. Is it correct? " << endl<< nl2 << endl;
cout << " Your information" << endl << endl;
cout << "========================" << endl;
cout << "Name : " << userName << endl;
cout << "Email : " << userEmail << endl;
cout << " About You :" << userInfo << endl;
cout << "Is the information Correct? Please enter 'Y' for Yes and 'N' for No " << endl;
cin >> userInput;
}
}
string userInput = "N";
while (userInput == "N")
{
^^ do/while avoids 'seeding' a value in a loop. Its not important here because the
variable creation and init works, but if the loop variable had already existed, you can avoid
seeding it like this:
do
{
...
cin>>userInput ;
...
} while (userInput == "N");
macros have type problems. its better to use constants, which strongly type the value. sure, its fine here in simple code, but in more complex code being unsure of the real type of those #defines can be annoying.