help on c++

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

kknla

Thread Starter
Joined
Jan 19, 2001
Messages
257
I am writing this project for school. I keep getting a parse error before `=' on about all the assignment statements in a certain function. I am tired or something, because I do not seem to see any errors. Anyone see what they are? Thanks ahead of time, Barret.
I am just listing the function, if you need more, just let me know.
Keep in mind, that I am new to this :)
adult, child, and senior_citizen have all beed predefined.

void get_subTotal (int age, char drink, float& subtotal, float& drink_price)
{
float price;
if (age < 12)
{
price = age * child;
}
else if (age >= 12 && age < 62)
{
price = adult;
}
else
price = senior_citizen;

if (drink == 'b' || drink == 'B')
{
drink_price = beer;
subtotal = price + drink_price;
}

else if (drink == 'c' || drink == 'C')
{
drink_price = coke;
subtotal = price + drink_price;
}
else
{
drink_price = water;
subtotal = price;
}
return;
}
 
Joined
Mar 18, 2001
Messages
1,741
You seem to have a bracket problem with your
if/else statements.

I'm assuming beer, coke, and water have been defined...

Code:
void get_subTotal (int age, char drink, float& subtotal, float& drink_price) 
{ 
  float price; 

  if (age < 12) 
     { price = age * child; 
     }
  else
     { if (age >= 12 && age < 62) 
          { price = adult; 
          }
       else 
          { price = senior_citizen; 
          }
     }

  if (drink == 'b' || drink == 'B') 
     { drink_price = beer; 
       subtotal = price + drink_price; 
     } 
  else
    { if (drink == 'c' || drink == 'C') 
         { drink_price = coke; 
           subtotal = price + drink_price; 
         } 
      else 
         { drink_price = water; 
           subtotal = price; 
         } 
    }

  return; 
}
Let me know if this helps. :)
 

kknla

Thread Starter
Joined
Jan 19, 2001
Messages
257
I am still getting the same errors. Here is all of my code. Everyhing was working fine up untill I wrote that fuction. Thanks.

//ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`
//
//
// Barret Kendrick
// CMPS 161
// 10-27-01
// Project 5
//
// This Program will ask the user for the drink he/she would like to have with
// his buffet order. It will then calculate everything and print the receipt
// for the user.
//
//ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`°¤ø,¸ ¸,ø¤°`°¤ø¤°`

#include <iostream.h>
#define coke = 1.20
#define beer = 2.10
#define water = 0.0
#define adult = 5.95
#define senior_citizen = 4.50
#define child = .45

void getAge (int& age);
void getDrink (int age, char& drink);
void get_subTotal (int age, char drink, float& subtotal, float& drink_price);

void main ()
{
int age;
char drink;
float subtotal;
float drink_price;

cout <<"Welcome to this program. I hope that it helps you to make your"
<<"work a little easier and quicker to complete.";
getAge (age);
getDrink (age, drink);
get_subTotal (age, drink, subtotal, drink_price);
}
//=============================start of getAge===============================
//This function will get the users age.
void getAge (int&age)
{
cout <<"\n\n\nHow old are you? ";
cin >>age;
return;
}
//==============================end of getAge================================

//============================start of getDrink==============================
//This function will get the users drink, and make sure he/she is old enough
//if they choose beer
void getDrink (int age, char& drink)
{
cout <<"\nWhat kind of drink would you like?"
<<"\n 'C' for coke"
<<"\n 'B' for beer"
<<"\n 'W' for water\n"
<<endl;
cin >>drink;

while (drink == 'B' || drink == 'b' && age < 21)
{
cout <<"\nYou are not old enough to drink beer."
<<"\nYou have to be at least 21 years old to purchase beer."
<<"\nYou are only " <<age <<" year(s) old."
<<"\nPlease choose something else.\n\n";
cin >>drink;
}

return;
}
//=============================end of getDrink===============================

//===========================start of subTotal===============================
//This function will calculate the subtotal for this customer.

void get_subTotal (int age, char drink, float& subtotal, float& drink_price)
{
float price;

if (age < 12)
{ price = age * child;
}
else
{ if (age >= 12 && age < 62)
{ price = adult;
}
else
{ price = senior_citizen;
}
}

if (drink == 'b' || drink == 'B')
{ drink_price = beer;
subtotal = price + drink_price;
}
else
{ if (drink == 'c' || drink == 'C')
{ drink_price = coke;
subtotal = price + drink_price;
}
else
{ drink_price = water;
subtotal = price;
}
}

return;
}

//============================end of subTotal================================
 
Joined
Mar 18, 2001
Messages
1,741
OK, here's some problems.

Your procedures should be "int" instead of "void"
so they can return the value back to main.
Otherwise the info you're getting from the user
doesn't get back to main. Make any sense?

This line also has errors:
Code:
&lt&lt"\nYou are only " &lt &lt&lt"\nPlease choose something else.\n\n";
No "age" after "You are only".

Give these a try and let me know what happens. :)
 
Joined
Mar 18, 2001
Messages
1,741
I forgot something...

The procedure that gets the drink type should
be a "char".

Sorry.
 
Joined
Mar 18, 2001
Messages
1,741
OK, never mind.

I'm asleep at the wheel here. I rarely use
pointers like your example, so give me a few
minutes on this.

Mac
 
Joined
Mar 18, 2001
Messages
1,741
Well, duh.

Your #defines shouldn't use the "=" sign.
Code:
#define coke 1.20  
#define beer 2.10 
#define water 0.0
#define adult 5.95 
#define senior_citizen 4.50 
#define child .45
Sorry I'm so dense tonight. :)
 

kknla

Thread Starter
Joined
Jan 19, 2001
Messages
257
I just had to kick myself for that one. Thanks, that cleared up most errors. I am still getting 2. Im getting a parse error before else, and a parse error at end of input.

void get_subTotal (int age, char drink, float& subtotal, float& drink_price)
{
float price;
if (age < 12)
{
price = age * child;
}
else
if (age >= 12 && age < 62)
{
price = adult;
else //this is where the first error is.
price = senior_citizen;
 
Joined
Mar 18, 2001
Messages
1,741
I've corrected some other errors, but haven't
checked your get_subTotal procedure for accuracy.
I'm attaching the code as a text file.

Code:
#include &ltiostream.h>

#define coke 1.20 
#define beer 2.10 
#define water 0.0 
#define adult 5.95 
#define senior_citizen 4.50 
#define child .45 

void getAge (int& age); 
void getDrink (int age, char& drink); 
void get_subTotal (int age, char drink, float &subtotal, float &drink_price); 

void main () 
{ 
  int age; 
  char drink; 
  float subtotal = 0; 
  float drink_price = 0; 

  cout <<"Welcome to this program. I hope that it helps you to make your" 
      <<"work a little easier and quicker to complete."; 
  getAge(age); 
  getDrink(age, drink); 
  get_subTotal(age, drink, subtotal, drink_price); 
} 

void getAge(int& age) 
{ 
  cout <<"\n\n\nHow old are you? "; 
  cin >> age; 
  return;
} 

void getDrink(int age, char &drink) 
{ 
  cout <<"\nWhat kind of drink would you like?" 
  <<"\n 'C' for coke" <<"\n 'B' for beer" <<"\n 'W' for water\n";
  cin >> drink; 

  while ((drink == 'B' || drink == 'b') && age < 21) 
        { cout << "\nYou are not old enough to drink beer." 
          <<"\nYou have to be at least 21 years old to purchase beer." 
          <<"\nYou are only " << age <<"\nPlease choose something else.\n\n"; 
          cin >> drink; 
        } 

  return; 
} 

void get_subTotal(int age, char drink, float &subtotal, float &drink_price)
{ 
  float price; 

  if (age < 12) 
     { price = age * child;
     }
  else
     { if (age >= 12 && age < 62) 
          { drink_price = adult; 
          }
       else 
          { drink_price = senior_citizen; 
          }
     }

  if (drink == 'b' || drink == 'B') 
     { drink_price = beer; 
       subtotal = price + drink_price; 
     } 
  else
    { if (drink == 'c' || drink == 'C') 
         { drink_price = coke; 
           subtotal = price + drink_price; 
         } 
      else 
         { drink_price = water; 
           subtotal = price; 
         } 
    }
  return; 
}
OK, the text file was a bad idea...
 
Joined
Mar 18, 2001
Messages
1,741
I removed the text file attachment and just
posted the code. I had no idea the text
attachment would be so scrambled...

Cheers, Mac
 

kknla

Thread Starter
Joined
Jan 19, 2001
Messages
257
When I downloaded the text file, it worked fine. I appreciate all your help, Barret. :D
 
Joined
Mar 18, 2001
Messages
1,741
One last thing (hopefully)...

I think "drink_price" in the following should
be "price". I believe I changed it while testing
and forgot to change it back...

Code:
  if (age >= 12 && age < 62)
     { drink_price = adult;
     }
  else
     { drink_price = senior_citizen;
     }
Cheers, Mac
 

kknla

Thread Starter
Joined
Jan 19, 2001
Messages
257
That is correct. I does need to be price. Hopefully, I can finish the rest of this error free. :D I am working on it now. So far, so good. Thanks again, Barret.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top