void sellTicket(bool guardianPresent, int movieRating, int age)
{
if (movieRating == 1 || guardianPresent) {
cout<< "You can see the movie."<<endl;
return;
}
cout<< "Please enter you're age: ";
cin>> age;
switch (movieRating) {
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: // Uhoh, 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() {
}
displayRatings();
/*
* File: main.cpp
* Author: Zac
*
* Created on October 6, 2015, 5:54 PM
*/
#include <iostream>
#include <cmath>
using namespace std;
displayRatings();
bool guardianPresent = false; // Provide a default restrictive state
int movieRating = 0; // Invalid initial state
int age = 0; // Provide a reasonably invalid initial restrictive state
cout<< "Which rating do you wish to watch? (Please enter corresponding number 1-4): ";
cin >> movieRating;
cout<< "Is there a guardian present? (Enter 1 for yes, and 0 for no) ";
cin >> guardianPresent;
sellTicket(guardianPresent,movieRating,age);
return 0;
}
}
void sellTicket(bool guardianPresent, int movieRating, int age)
{
if (movieRating == 1 || guardianPresent) {
cout<< "You can see the movie."<<endl;
return;
}
cout<< "Please enter you're age: ";
cin>> age;
switch (movieRating) {
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: // Uhoh, 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
}
cout<< "Which rating do you wish to watch? (Please enter corresponding number 1-4): ";
cin >> movieRating;
cout<< "Is there a guardian present? (Enter 1 for yes, and 0 for no) ";
cin >> guardianPresent;
sellTicket(guardianPresent,movieRating,age);
return 0;
}
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/main
mkdir -p build/Debug/GNU-MacOSX
rm -f "build/Debug/GNU-MacOSX/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/GNU-MacOSX/main.o.d" -o build/Debug/GNU-MacOSX/main.o main.cpp
main.cpp:56:12: error: function definition is not allowed here
int main() {
^
main.cpp:62:6: error: redefinition of 'guardianPresent'
bool guardianPresent = false; // Provide a default restrictive state
^
main.cpp:18:22: note: previous definition is here
void sellTicket(bool guardianPresent, int movieRating, int age)
^
main.cpp:63:5: error: redefinition of 'movieRating'
int movieRating = 0; // Invalid initial state
^
main.cpp:18:43: note: previous definition is here
void sellTicket(bool guardianPresent, int movieRating, int age)
^
main.cpp:64:5: error: redefinition of 'age'
int age = 0; // Provide a reasonably invalid initial restrictive state
^
main.cpp:18:60: note: previous definition is here
void sellTicket(bool guardianPresent, int movieRating, int age)
^
main.cpp:70:1: error: void function 'sellTicket' should not return a value [-Wreturn-type]
return 0;
^ ~
5 errors generated.
make[2]: *** [build/Debug/GNU-MacOSX/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2