#include <cstdlib>
#include <iostream>
#include <string>
usingnamespace std;
int main(int argc, char *argv[])
{
string FirstLine="";
//need an int variable
int choicevariable = 0;
cout << "Welcome to The Time Machine" << endl << endl;
cout << "What is your Name?";
getline(cin, FirstLine);
//display user's name
cout << "HI " << FirstLine << endl << endl;
cout << "Select an option to get started:" << endl;
// i get stuck trying to figure out how to loop this part i know what parts i have to loop i am just not sure how.
while (choicevariable < 1 || choicevariable > 3)
{
cout << "1. Enter a Specific Date" << endl;
cout << "2. Select a Time Period" << endl;
cout << "3. Wildcard - I'm Feeling Lucky" << endl << endl;
//get the user's choice using your int variable and cin
cout << "Enter your choice: ";
cin >> choicevariable;
cin.clear();
cin.ignore(100, '\n');
}
//display thier choice
cout << "#" << choicevariable << endl;
int Month = 0;
int Day = 0;
int Year = 0;
while (Month < 1 || Month > 12)
{
cout << "What is the Month?" << endl;
cin >> Month;
}
while (Day < 1 || Day > 7)
{
cout << "What is the Day?" << endl;
cin >> Day;
}
cout << "What is the Year?" << endl;
while(!(cin >> Year)){
cin.clear();
cin.ignore(100, '\n');
}
cout << " Ok, We will send you to" << endl;
cout << "Ending Program";
if (choicevariable == 2)
{
int timePeriod;
cout << "Choice from one of the time periods:" << endl << endl;
cout << "1. Prehistoric Dinosaur Era" << endl;
cout << "2. Pirate Era" << endl;
cout << "3. Five Days ago" << endl;
cout << "4. Mideval" << endl;
cin >> timePeriod;
cout << " Ok, We will take you to" << timePeriod << endl;
cout << "Ending Program";
}
if (choicevariable == 3)
{
cout << "Ok, I'll choose where to send you" << endl;
}
elseif (choicevariable > 3)
cout << "Choice Not Valid" << endl;
cout << "Ending Program" << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
Use a switch statement and an enumeration to select the month.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
enum MonthEnums
{
JAN = 1,
FEB = 2,
...
}
// Inside your function
string monthstr;
switch (Month)
{
case JAN:
monthstr = "January";
break;
case FEB:
...
}
This way, you can even keep track of invalid input, such as if user enters something 0 or below or 13 and above using a default case.
can i use this way without changing any of the code ? It has to do what it does polus the array and i keep getting errors with adding the string and switch part ?