The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 327 Weeks Ago, 4 Days Ago |
| Questions Answered: | 12843 |
| Tutorials Posted: | 12834 |
MBA, Ph.D in Management
Harvard university
Feb-1997 - Aug-2003
Professor
Strayer University
Jan-2007 - Present
Week 5: Add arrays to your program to handle more data.
Examples: In the programming tutorial, add a tutorial on working with arrays. Then use arrays to
store the answers to multiple questions so that you can compute a total score.
“ This week I am adding arrays to this program” #include <iostream> using namespace std; int main()
{
char ch='Y';
int gateNo; // integer for gate number
int choice;
cout << "Menu" << endl;
cout << "1. Check movies, their time and gate\n2. Exit\n";
//validate user input in a loop
while(true) {
cin >> choice;
if(choice < 1 || choice > 2) {
cout << "Menu" << endl;
cout << "1. Check movies, their time and gate\n2. Exit\n";
} else {
break;
} }
if(choice == 1) {
cout << "Movies with their time and gate..." << endl; while( ch=='y' || ch=='Y'){ //user prompt for gate number
cout << "1. Movie: Beauty and the beast\n2. Movie: The Circle\n3. Movie: Boss Baby\n"; while(true) {
cout << endl <<"Please enter the Gate number : ";
cin >> gateNo;
if(gateNo < 1 || gateNo > 3) {
cout << "Invalid gate no!!" << endl;
continue;
}
break;
} // details of movies...
if (gateNo == 1) {
cout << endl << "Movie: Beauty and the beast" << endl;
cout << "Time: 1:00pm" << endl;
cout << "Gate: 1" << endl; }
else if (gateNo == 2) {
cout << endl << "Movie: The Circle" << endl;
cout << "Time: 3:00pm" << endl;
cout << "Gate: 2" << endl;
}
else if (gateNo == 3) {
cout << endl << "Movie: Boss Baby" << endl;
cout << "Time: 5:00pm" << endl;
cout << "Gate: 3" << endl;
}
else {
cout << "Please enter a valid gate number !" << endl;
} // user prompt to continue
cout << endl << "To cont... press[Y/N]: ";
cin >> ch;
}
} cout << "Thanks for using Movies menu program!" << endl;
system("pause");
return 0;
}
-----------