Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

help on c++


(!)

kknla's Avatar
kknla kknla is offline
Member with 257 posts.
THREAD STARTER
 
Join Date: Jan 2001
Location: New Orleans, Louisiana
Experience: Advanced
03-Nov-2001, 11:38 PM #1
Question help on c++
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;
}
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
03-Nov-2001, 11:53 PM #2
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's Avatar
kknla kknla is offline
Member with 257 posts.
THREAD STARTER
 
Join Date: Jan 2001
Location: New Orleans, Louisiana
Experience: Advanced
04-Nov-2001, 12:01 AM #3
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================================
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 12:16 AM #4
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.
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 12:24 AM #5
I forgot something...

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

Sorry.
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 12:31 AM #6
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
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 01:02 AM #7
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's Avatar
kknla kknla is offline
Member with 257 posts.
THREAD STARTER
 
Join Date: Jan 2001
Location: New Orleans, Louisiana
Experience: Advanced
04-Nov-2001, 01:13 AM #8
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;
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 01:14 AM #9
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...

Last edited by MacFromOK; 04-Nov-2001 at 01:20 AM..
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 01:16 AM #10
I'm also outta here for tonight. I'll try to check back
tomorrow.

Cheers, Mac
kknla's Avatar
kknla kknla is offline
Member with 257 posts.
THREAD STARTER
 
Join Date: Jan 2001
Location: New Orleans, Louisiana
Experience: Advanced
04-Nov-2001, 01:17 AM #11
thanks again
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 01:22 AM #12
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's Avatar
kknla kknla is offline
Member with 257 posts.
THREAD STARTER
 
Join Date: Jan 2001
Location: New Orleans, Louisiana
Experience: Advanced
04-Nov-2001, 01:33 AM #13
When I downloaded the text file, it worked fine. I appreciate all your help, Barret.

Last edited by kknla; 04-Nov-2001 at 01:49 AM..
MacFromOK's Avatar
Senior Member with 1,741 posts.
 
Join Date: Mar 2001
Location: Oklahoma
Experience: idiota de la aldea
04-Nov-2001, 12:37 PM #14
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's Avatar
kknla kknla is offline
Member with 257 posts.
THREAD STARTER
 
Join Date: Jan 2001
Location: New Orleans, Louisiana
Experience: Advanced
04-Nov-2001, 01:26 PM #15
That is correct. I does need to be price. Hopefully, I can finish the rest of this error free. I am working on it now. So far, so good. Thanks again, Barret.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑