code errors

Write your question here.

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



closed account (48T7M4Gy)
 In function 'void sellTicket(bool, int, int)':
 56:1: error: expected ';' before 'int' 65:8: error: return-statement with a value, in function returning 'void' [-fpermissive]


Hint: brace yourself for an error at line 56

PS ru a bot?
Last edited on
how do i fix?
closed account (48T7M4Gy)
Follow the hint
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/175477/
i take away the brace in line 56
what about error 65:8
kermit i dont understand these errors
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
int main()
{
   //program
   return 0;
}

void function()
{
   //program
   return;
}


Typical program structure. Debug cycle consists of - first error/repair/ compile/check errors.
what about error 65:8

Why are you not telling us what the error message is? Do you think that withholding information from us is going to help us solve your problem?

Where to begin? The first problem with your code, (and there are a few problems. I'll touch on them all) is formatting. It's hard for you to see your errors because its sloppy. You have to look for the curly brackets, I was running around hunting for ;'s. Consistency of format is one of your most valuable tools. Put a line or two in between your functions so you know where one starts and the other ends. When you open or close a function place you curly brackets on their own line. You have plenty of lines, don't be afraid to use them and space your code out.
Not only that, when everything is on separate lines, you have less code to search through to find your errors.

1
2
3
4
5
6
7
8
9
10
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 


Is easier to debug than this

1
2
3
4
case 2:
if (age>=10) { cout<< "You can see the movie."<<endl;} 
else {cout<< "You can not see the movie."<<endl;}
break;



Now for your code....

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

 

Topic archived. No new replies allowed.