undclared identifier

i keep getting the error for an undeclared identifier for customerprice, customerprice2, customerprice3,ticketamt help i can't figure it out

# include<iostream>
# include<string>
# include<iomanip>

using namespace std;
double get_ticket_type (double ticketchoice1,double ticketchoice2,double ticketchoice3, double ticketchoice4);
double find_ticket_price (double customerprice, double customerprice2, double customerprice3, double ticketamt);

int main()

const double MAX_SEAT_COUNT=10;
double ticketchoice=0.0;
double ticketchoice2=7.50;
double ticketchoice3=11.50;
double ticketchoice4=0;
double ticketamt;
double customerprice=0;
double customerprice2=0;
double customerprice3=0;
double ticketaccum=0;
double totalprice=0;
double discount=.25;
double discountprice=0;
int choice;


cout << "Please select from one of the following\n"

"\n 1. Toddler (free tickets)\n"
"\n 2. Juniors \n"
"\n 3. Seniors\n"
"\n 4. Quit \n ";

cin >> ticketchoice;

cin >> ticketamt;

customerprice=find_ticket_price(customerprice,customerprice2,customerprice3, ticketamt);

ticketchoice= get_ticket_type(ticketchoice, ticketchoice, ticketchoice3,ticketchoice4);

cin >> ticketamt;



while (ticketaccum!=MAX_SEAT_COUNT);

cout << "any discounts";
cin >> choice;
if (choice==1)

cout << discountprice;
cout <<customerprice;
cout <<fixed;
cout <<fixed;
cout << totalprice<<endl;
cout<< fixed;
cout<< ticketaccum<<endl;
cout<< fixed;
cout<< customerprice<<endl;

system ("pause");

double get_ticket_type (double ticketchoice,double ticketchoice2,double ticketchoice3, double ticketchoice4)

if (ticketchoice==1|| ticketchoice==2 || ticketchoice== 3 || ticketchoice == 4)
{cout << "please enter ticket amoutn"<<endl;

if (ticketchoice!=1|| ticketchoice!=2 || ticketchoice!= 3 || ticketchoice != 4)

cout << "Error please reenter choice";

return (ticketchoice);

double find_ticket_price (double customerprice, double customerprice2, double customerprice3,double ticketamt);

if (ticketchoice==1)

if (ticketchoice==2)
if (ticketchoice==3)
{ customerprice3=ticketamt*ticketchoice3;
return (0);
First, please edit your post to include the code brackets, it's the <> button. After you do that you'll prolly have to repaste your code between them since you've already lost all the indentations that make reading code a bit easier. Now then

Variables declared in a function only have scope within that function. That includes main. The only way to work with a variable that is declared in main in another function, even one called from main, is to pass that variable to the function as an argument. Now, with that in mind, when you write a function declaration any variables you declare in it (or in the subsequent body of the function) ALSO only have scope in that function. So, for instance, in your find_ticket_price function you are passing customerprice, customerprice2, customerprice3 to the function, but you are passing by value. Meaning the program creates a COPY of the argument and uses that. Even though the variables in the function are the same name as the ones in main they are NOT the same variables, they are new copies with their own values. As soon as find_ticket_price ends execution those variables disappear and so does the work you did.

There's 2 ways around this. 1 is to return the value you want. Unfortunately you can only return 1 value this way. If you have multiple variables that you need to work on then you must pass those variables by reference to the function. What this does is basically pass the variables' location to the function and creates an alias for each variable within the function. This way you can modify more then 1 variable within the function and you don't even have to return anything.

Beyond that, you have some issues with your inputs and such, namely with customerprice=find_ticket_price(customerprice,customerprice2,customerprice3, ticketamt);. You are passing arguments to the function that you haven't even entered values into yet.

Anyway, there's a start for ya.
i actually fixed the identifier problem somehow really dont know how but i did but now its saying syntax error with my very last curly bracket and im really not sure why but when i remove it it has a fatal error it also tells me missing ; before } but i have no where to put that ; so im lost
Topic archived. No new replies allowed.