1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
/*
* File: main.cpp
* Author: Zac
*
* Created on October 6, 2015, 5:54 PM
*/
#include <iostream>
#include <cmath>
// Why do you include the cmath library? It serves no purpose.
using namespace std;
void displayRatings() {
cout << "1. G Rating."<<endl;
cout << "2. PG Rating."<<endl;
cout << "3. PG-13."<<endl;
cout << "4. R." <<endl;
}
void sellTicket(bool guardianPresent, int movieRating, int age)
{
if (movieRating == 1 || guardianPresent) {
// Is this the beginning of your first case? How do you know? Where is the switch statement?
cout<< "You can see the movie." <<endl;
return;
}
cout<< "Please enter you're age: ";
cin>> age;
// Why are you asking for input here, after you've started the solution process? This should be elsewhere in the code.
switch (movieRating) {
// Oh!!! Here's the switch... A little late considering you're on case 2 already. :)
case 2:
if (age>=10) {
cout<< "You can see the movie."<<endl;
} else {
cout<< "You can not see the movie."<<endl;
}
break; // Exit the switch, go to the closing brace of the switch
case 3:
if (age>=13) {
cout<< "You can see the movie."<<endl;
} else {
cout<<"You can not see the movie."<<endl;
}
break;
case 4:
if(age>=17) {
cout<< "You can see the movie."<<endl;
} else {
cout<< "You can not see the movie."<<endl;
}
break;
default: // Uh oh, someone entered a number that isn't 1, 2, 3, or 4
cout << "You need to choose a valid movie rating" << endl;
displayRatings()
// Note the default case at the end does not need a break statement
int main() }
// Whoops.. Look at that curly bracket...
displayRatings();
cout<< "Which rating do you wish to watch? (Please enter corresponding number 1-4): ";
cin >> movieRating;
// Is movieRating declared?
cout<< "Is there a guardian present? (Enter 1 for yes, and 0 for no) ";
cin >> guardianPresent;
// Is guardianPresent declared?
sellTicket(guardianPresent,movieRating,age);
// Hmmm You ask 2 questions and want to send 3 parameters. That's odd. Maybe you misplaced the third question in wrong part of the program.
return 0; }
|