code error


/*
* 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();

/*
* 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;

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;
}


}


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;
}
Last edited on
closed account (48T7M4Gy)
... and the question is ...
"/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

BUILD FAILED (exit value 2, total time: 265ms)
closed account (48T7M4Gy)
OK, I assume that means you want help with the errors.

The first thing you need to do is put code tags around your OP so that we can see line numbers.

However, your first erro is you have a program main with nothing in it because the second brace is wrong.

1
2
3
int main() {

}
Last edited on
closed account (48T7M4Gy)
see http://www.cplusplus.com/forum/beginner/175481/
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/175490/
Topic archived. No new replies allowed.