I NEED HELP QUICK. I need help with this assignment, it's due by midnight. This is what i have to do: In addition to the existing main() function you will have three user-defined functions. These functions must be defined AFTER the main() function. That means you must use a function prototype for each function you create. Here is the breakdown of the required functions:
A void function that will display the opening menu.
A void function that will display the time periods menu.
A value-returning function that will get a valid number from the user. This function should be reused for the Main Menu, Month, Day and Time Periods. You can use it for the year if you want to give a span for the number of years, but it is not required. It must validate it to make sure it is a number between the possible options. If the entry is not correct, it must loop until a correct option is entered.
The time machine program should work as before, the only difference is now it will use the three user-defined functions you will create.
This is what i have. Please help quickly.
#include "stdafx.h"
#include "conio.h";
#include "iostream";
#include "string";
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int choice;
char name[20];
string months[12]= {"January" , "Febaurary" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" };
cout<<"Welcome to the Time Machine "<<endl;
cout<<"What is you name ?"<<endl;
cin>>name;
cout<<"welcome "<< name <<endl;
cout<<"\n";
cout<<"1- Enter a specific date"<<endl;
cout<<"2. Select a Time Period"<<endl;
cout<<"3. Wildcard - I'm Feeling Lucky"<<endl;
cin>>choice;
if(choice == 1)
{
int month;
int day;
int year;
cout<<"What is the month? (enter 1-12)"<<endl;
cin>>month;
cout<<"What is the day? (enter 1-31)"<<endl;
cin>>day;
cout<<"What is the year?"<<endl;
cin>>year;
cout<<"OK we will send you to "<<months[month-1]<<"/"<<day<<"/"<<year<<endl;
cout<<"\n";
cout<<"Ok Ending the time machine program";
}
elseif(choice == 2)
{
int tperiod_choice;
cout<<"\n";
cout<<"Choose from one of these time periods."<<endl;
cout<<"\n";
cout<<"1. Prehistoric Dinosaur Era"<<endl;
cout<<"2. 500 BC"<<endl;
cout<<"3. Renaissance"<<endl;
cout<<"3. Renaissance"<<endl;
cout<<"4. American Civil War"<<endl;
cin>>tperiod_choice;
cout<<"\n";
cout<<"Ok We will send you to choice "<<tperiod_choice<<endl;
}
elseif(choice == 3)
{
cout<<"\n";
cout<<"Ok i will choose where to send you"<<endl;
}
else
{
cout<<"your choice is not valid"<<endl;
}
getch();
return 0;
}
Anyways, you should try to follow the instructions and write the 3 functions you were told instead of putting everything in main. It makes it much clearer to read.
As per your instructions, you'll want to declare the function prototypes before your main function:
1 2 3
void openingMenu();
void timePeriodsMenu();
int getValue( int lowerBound, int upperBound, istream &in = cin);
The above code is a possible choice for the function prototypes, though you can probably do without specifying the input stream.
Those were function prototypes. They're basically there to tell your compiler those functions exist so they can be used. You the have to define them later in the file. Therefore, they'll go right after your preprocessor commands (#include) and your usingnamespace std;.
Do note you still have to define (write all the code for) the functions though.
For openMenu(), the relevant code in main would be lines 19-27. For void timePeriodsMenu();, the relevant code would be 49-61. Just copy the code into your new function definitions and make the necessary changes.