# include <iostream>
#include <string>
usingnamespace std;
int main ()
{
int choice, s;
string name, title;
cout<<"********* Welcome to my program **********"<<endl;
cout<<"\t 1: name"<<endl;
cout<<"\t 2: title"<<endl;
cout<<"\t 3: speed"<<endl;
cout<<"\t 4: Exit"<<endl;
cout<<endl;
cout<<"Please make your selection: ";
cin>>choice;
cout<<endl;
cin.get();
if (choice<1 || choice>=5)
{
cout<<"You have enetered an invalid option, please try again..."<<endl;
}
if (choice == 4) {exit(EXIT_FAILURE) ;}
switch (choice)
{
case 1:
cout<<"Please enter the name: ";
getline (cin,name);
break;
case 2: cout<<"Please enter the title : ";
getline (cin,title);
break;
case 3: cout<<"Please enter the speed (1-100): ";
cin>>s;
break;
}
cout<<"Thank you for playing "<<endl;
cin.get();cin.get();
return 0;
}
I want somewhere at the end to prompt the uset to continue press y or n
No. You could declare it as an std::string... eh... it would be a good idea to declare it as a character, yes, if the only thing that will get the loop to rerun is a y or Y response from the user. If you want to also be able to type "Yes" or longer phrases to get it to rerun, then std::string.
By default, the loop quits if you type anything other than Y and y. But, if you want the whole program to exit if you type N or n and bypass anything outside the loop, try returning 0 inside an if statement just outside the loop (after the while()).