errors

/*
* File: main.cpp
* Author: Zac
*
* Created on October 6, 2015, 5:54 PM
*/
#include <iostream>
#include <cmath>
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) {
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();
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;
}






In function 'void sellTicket(bool, int, int)':
56:12: error: a function-definition is not allowed here before '{' token
62:6: error: declaration of 'bool guardianPresent' shadows a parameter
63:5: error: declaration of 'int movieRating' shadows a parameter
64:5: error: declaration of 'int age' shadows a parameter
70:8: error: return-statement with a value, in function returning 'void' [-fpermissive]
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/175457/
Please don't start multiple threads for the same problem.

You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
If you're not going to make the slightest bit of effort to make your posts readable, why should we spend the slightest bit of effort helping you?
I will not respond further until you apply code tags.
Closing curly braces at start of main() function, meaning that all after it are not actually within the main function at all. Move the curly brace before the int main() function start line (as the end curly brace is missing from the previous function.

Try that and it should be fine (apart from indentation - if using dev-cpp tool, highlight the whole text and click Tab; if using MS Dev Studio highlight and click Alt+F8 (I think)
Last edited on
Topic archived. No new replies allowed.