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