Error: expected constructor before '<' token

Hello all! Forgive me I am new so I'm not sure how to format posts.

I'm doing a simple program to calculate the cost of a meal, tax, tip, and total and I've checked it 800 times and I cannot seem to find the error it is speaking of?

Could someone help me?



1
2
3
4
5
p1.cpp:118: error: expected constructor, destructor, or type conversion before '<<' token
p1.cpp:120: error: expected constructor, destructor, or type conversion before '<<' token
p1.cpp:122: error: expected constructor, destructor, or type conversion before '<<' token
p1.cpp:123: error: expected unqualified-id before "return"
p1.cpp:124: error: expected declaration before '}' token


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
#include <iostream>
#include <iomanip>
using namespace std;

int main ()

{

     double meal;
     double tax;
     double tip;
     double total;

     meal = 34.25;
     tax = 0.0525 * 34.25;
     tip = 0.2 * 34.25;

cout << "Meal cost: $" << meal << endl;

cout << setprecision (2) << fixed;

cout << "Tax amount: $" << tax << endl;

cout << "Tip amount -20%-: $" << tip << endl;

       total = meal + tax + tip;

cout << "Total amount: $" << total << endl;

return 0;
}


Last edited on
Is this all of the code? I don't see an issue here. And the error message seems to say that there at least 124 lines of code, which this does not.
Yes, this is all of the code. I copied the error message from my compiler screen and retyped the code when I posted this. So that's why the line numbers don't match up.

If it looks like nothing is wrong then why isn't it compiling?
Copy and paste your exact code, do not retype it by hand.

Okay, here it is copy and pasted. But the line numbers still won't match up.


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
#include <iostream>
#include <iomanip>
using namespace std;

int main ()

{

double  meal;
double  tax;
double  tip;
double  total;

meal = 34.25;

tax = 0.0525 * 34.25;

tip = 0.2 * 34.25;

cout << "Meal cost: $" << meal << endl;

cout << setprecision (2) << fixed;

cout << "Tax amount: $"  << tax << endl;
cout << "Tip amount -20%-: $" << tip << endl;

   total =  meal + tax + tip;
cout << "Total amount: $" << total << endl;

return 0;
}


"p1.cpp" 126 lines, 758 characters 
admiral% g++ p1.cpp
p1.cpp:118: error: expected constructor, destructor, or type conversion before '<<' token
p1.cpp:120: error: expected constructor, destructor, or type conversion before '<<' token
p1.cpp:122: error: expected constructor, destructor, or type conversion before '<<' token
p1.cpp:123: error: expected unqualified-id before "return"
p1.cpp:124: error: expected declaration before '}' token
Again
> Don't post code which is different from your own but does not reproduce the problem
¿what you don't understand?
The code you posted compiles fine, stac101.
Topic archived. No new replies allowed.