expected primary-expression before "const" c++

Oct 29, 2011 at 4:23pm
Trying to figure out why i am getting this error:

#include <iostream>
#include <iomanip>

using namespace std;

int main ()
{
const double g-v = 125.00,
const double p-v = 145.00,
const double l-v = 180.00;
char g,
p,
l,
v;
double room_type,
rate,
frig,
bed,
gt;
int days;

//Get information from the user

cout << setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);

cout << "Enter your room type ('g' for garden view, 'p' for pool view, or 'l' for lake view: ";
cin.get();
room_type = cin.get();

cout << "Enter your number of day you stayed: ";
cin >> days;

cout << "Did you have a refrigerator (y/n): ";
cin.get();
frig = cin.get();

cout << "Did you have an extra bed (y/n): ";
cin.get();
bed = cin.get();

//Calculate and output the results

if (room_type = 'g')
rate = g-v * days;
if (room_type = 'p')
rate = p-v * days;
if (room_type = 'l')
rate = l-v * days;
if (frig = 'y')
frig = days * 2.5;
else
frig = 0;
if (bed = 'y')
bed = days * 15.00;
else
bed = 0;
gt = rate + frig + bed;

//output the results

cout << "The room type you stayed in was the: " << setw(14) << room_type << endl;
cout << "The number of days you stayed was: " << setw(14) << days << endl;
cout << "Your basic room rate was: " << setw(14) << rate << endl;
cout << "Your charge for a refrigerator was: " << setw(14) << frig << endl;
cout << "Your charge for an extra bed was: " << setw(14) << bed << endl;
cout << "Your total charge for the stay is: " << setw(14) << gt << endl;

return 0;
}
Oct 29, 2011 at 4:36pm
In your variable declarations, you are using , instead of ;. It's saying that after the comma, it expects another variable name rather than another type name.

For example, you can:
1
2
3
4
5
6
7
8
9
10
// same type:
int a, b, c;
// different types:
int a;
double b;
const int c;
// or you could list same types the "long" way:
int a;
int b;
int c;
Oct 29, 2011 at 4:38pm
Also, you cannot use a minus in a variable name, for obvious reasons.
Oct 29, 2011 at 4:53pm
thanks got it worked out. now to work on the calculations and output.
Oct 29, 2011 at 5:31pm
output is good, any suggestions on the calculations?
Topic archived. No new replies allowed.