Help with error

am getting expected ')' before my if else statements.

[code


if (guests 25<)
{
cost_cake =(SHEET_CAKE);
}
else (guests <=25)
{
cost_cake = (HALF_CAKE);
}
return cost_cake;
}

//Calculations for balloons

balloonNum = (guests * age);

if (balloonNum <=50)
{
balloonCost = (balloonNum * BALLOON_COST);
}
else if (balloonNum 50<) || ( <=100)
{
balloonCost = (balloonNum * BALLOON_COST2);

}
else (balloonNum 101<=)
{
balloonCost = (balloonNum * BALLOON_COST3);
}

return balloonCost;
}
// balloonNum = (guests * age);
// balloonCost = (balloonNum * BALLOON_COST);

//Calculations for gift bags
giftbagNum = guests;
giftbagCost = (giftbagNum * GIFTBAG_COST);

//Calculations for napkins
napkinNum = ceil(((guests + 1) * 4)/NAPKIN_PER_PACK); //**round up

if (napkinNum <=100)
{
napkinCost = (napkinNum * NAPKIN_COST);
}
else if (napkinNum 101<=) || (<=299)
{
napkinCost = (napkinNum * NAPKIN_COST2);
}
else (napkinNum 300<=)
{
napkinCost = (napkinNum * NAPKIN_COST3);

}
return napkinCost;
}

// napkinCost = (napkinNum * NAPKIN_COST);

//Calculations for plates
plateNum = ceil(((guests +1) * 2)/PLATE_PER_PACK) //**round up


if (plateNum <=50)
{
plateCost =(plateNum * PLATE_COST);
}
else (plateNum 50<)
{
plateCost = (plateNum * PLATE_COST);
}
return plateCost;
}
// plateCost = (plateNum * PLATE_COST);

//Calculations for pizza
pizzaNum = ceil(((guests + 1) * 3)/PIZZA_SLICES); //**round up
pizzaCost = (pizzaNum * PIZZA_COST);

//Calculations for juice boxes
juiceboxNum = ceil(((guests + 1) * 2)/JUICEBOX_PER_PACK); //*round up
juiceboxCost = (juiceboxNum * JUICEBOX_COST);

//Calculations for the total party cost
totalPartyCost = (balloonCost + giftbagCost + napkinCost + plateCost + pizzaCost + juiceboxCost + cost_cake);

//output section
outFile.open(fileName.c_str(),ios::app);



//Output the results
outFile << endl << endl << endl;
outFile << setprecision(2) << fixed << showpoint;
outFile << "Balloons:" << setw(10)<< balloonNum << setw(8) << "$" << balloonCost << endl;
outFile << "Gift bags:" << setw(8) << giftbagNum << setw(8) << "$" << giftbagCost << endl;
outFile << "Napkin packs:" << setw(6) << ceil(napkinNum) << setw(8) << "$" << napkinCost << endl;
outFile << "Plate packs:" << setw(8) << ceil(plateNum) << setw(8) << "$" << plateCost << endl;
outFile << "Pizzas:" << setw(12) << ceil(pizzaNum) << setw(8) << "$" << pizzaCost << endl;
outFile << "Juice boxes packs:" << setw(2) << ceil(juiceboxNum) << setw(6) << "$" << juiceboxCost << endl;
outFile << "Cake:" << setw(23) << "$" << cost_cake << endl;
outFile << "Total cost:" << setw(18) << "$" << totalPartyCost << endl;
outFile << endl << endl << endl << endl;
outFile <<" ****************************************" <<endl;
outFile.close();


return 0;


][/code]
Last edited on
you pasted in a way that broke the code tags. Good try, but it didn't help us reading it a bit.


if (guests 25<)
that is not right.
maybe you meant
if (guests < 25) //if guests is less than 25

also
else (guests <=25)
is not right either.
c++ syntax is
if (condition)
{
do things that happen if the condition was true
}
else //else is optional. else does not have any conditions on it.
{
do things that happen if it was false.
}

you can nest them. c++ does not have an else if, but you can just lump them to the same effect:
if(condition)
else if (other condition) //really an else statement followed by a new if statement. the new if is the body of the else.
{
inside the second if statement.
}
so if condition is true, it does something, if it is false it checks other condition, and if that is true, does the inside the 2nd if part. another else would do that part if the second condition were false. and so on.

cost_cake =(SHEET_CAKE);
this is not wrong but you don't need the () around it.

else if (napkinNum 101<=) || (<=299)
this is also gibberish to c++.
c++ is explicit, you can't say if x is 10 or 11. you have to say if x is 10 or x is 11. and again the operators are out of order in the first part.
try
if(napkinNum <= 101 || napkinNum <= 299) //this is the right syntax
//but it is still silly: if its <= 101 it is always <= 299, why not just say <= 299?
something here is redundant/ not useful.
Last edited on
Hello softballer3,

Bear with me this is just a copy and paste.


PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.

Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.

http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/

Hint: You can edit your post, highlight your code and press the <> formatting button, but you may still to indent your code.

You can use the preview button at the bottom to see how it looks.

I found the second link to be the most help.



When I was looking over your code I see many problems. First you have no"#include" files, no definition of the constant variables like, "SHEET_CAKE" and no "main" function. In short there is not enough to compile and test the program. It is usually best to post the whole code or at least enough to duplicate the problem.

In this case posting the whole code is needed. I suspect that you did not post the whole code because it is not written yet.

Given the piece of code:
1
2
3
4
5
6
7
8
9
10
if (guests 25<)
{
cost_cake =(SHEET_CAKE);
}
else (guests <=25)
{
cost_cake = (HALF_CAKE);
}
return cost_cake;
}

Lines 9 and 10 suggest that this should be a function, but you are missing the function definition.

I think what you want is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int CakeCost(int numGuests)
{
	int cost_cake{};

	if (numGuests 25 < ) // <--- syntax error.
	{
		cost_cake = SHEET_CAKE;  // <--- Undefined.
	}
	else (numGuests <= 25)
	{
		cost_cake = HALF_CAKE;  // <--- Undefined.
	}

	return cost_cake;
}

Not knowing what you are needing to work with I made everything an "int" for now, but "int" may not work.

The same concept is needed for the rest of the code you posted.

The output section could either be a function or put near the end of "main"
1
2
3
4
5
6
7
8
9
10
11
12
13
//output section
outFile.open(fileName.c_str(), ios::app);// <--- The ".c_str()" is not needed from C++11 on.

outFile << setprecision(2) << fixed << showpoint;  //<--- Only needs done once unless changed.

//Output the results

outFile << endl << endl << endl;
//outFile << "\n\n\n";  // <--- previous line could be written this way.

outFile
	<< "Balloons:" << setw(10) << balloonNum << setw(8) << "$" << balloonCost << '\n'
	<< "Cake:" << setw(23) << "$" << CakeCost(numGuests) << endl;

First you do not need all the "endl"s that you have. As I have read in the past the "endl" comes with overhead to flush the output buffer and add the carriage return and line feed. Most of the time the "\n" will and I save the "endl" for the last line.

Line 13 demonstrates a way of using the return value of the function to print what you need to the file.

Lines 11 - 13 show you a way of writing the "outFile" statement in what would be one single line, but in a way that is easy to read and work with.

After the output section you have return 0;. I do not know if this is meant to be a return from a function, if so it is not needed, or the return from "main", again not necessary, but can be useful, and I think it is just good form.

Last point: if this is for school and even if it is not post the instructions for what is needed. This helps to see if you are coding in the right direction.

Andy
Topic archived. No new replies allowed.