@kroaken
@niccolo I am actually in my third year of my Bachelor's program. I just happened to get a professor that has a lot going on in their personal life and it has affected their ability to teach this semester. I am only making this post because I am having to teach myself an entire course and am just in desperate need of help. |
I'm sympathetic, and I wasn't really aiming anything at you, it was just @Repeater, with something of a valid point, was just in a position to hit my funny bone.
@dhayden has much more pertinent help for you than I offered.
I'll try better.
Ok, in main, this line:
void copyRightInfo();
Looks like a function declaration, which you have correctly shown just above main in your declaration section. Unfortunately, there's no actual copyRightInfo() function defined. What appears in your text LOOKS to a human like what you intend as the definition of the copyRightInfo function, but it is contained inside the main function, and that's not allowed.
@dhayden thoughtfully exampled how the copyRightInfo function should appear. It is below and outside the main function.
@dhayden's example didn't happen to call the function, which would merely be a line like the following near or at the top of the main function, something like
1 2 3 4 5 6
|
int main()
{
copyRightInfo();
//....then the rest of the main function
} // <<<<<<<<<<<<<<<<<<<<<<<< this ends the main function
| |
Now we come to the read data function definition. The top line of that reads thus in your post:
1 2 3 4 5 6 7 8 9 10 11 12
|
bool readData(string inventoryNames[], float inventoryCost[]);
{
bool readFile = false;
//Finish all the code Program 7-7
const int ARRAY_SIZE = 10; // Array size
int numbers[ARRAY_SIZE]; // Array with 10 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input file stream object
//....................................the rest of the readData function
} // closes the readData function
| |
The initial problem here is the ";" in the first line. A function definition must take this form
Note the absence of a ";" after "foo()". The semicolon would make the line a declaration, which by itself is ok (and you have that at the top of the text correctly), but here the text must proceed into the definition with an opening "{", not a ";"
It is an error you tend to repeat, which is why I detail it here.
In the case of mkIndex in your text we're left a bit puzzled. @dhayden worked that out by moving that code into main, but consider this simplified example of what your text does:
1 2 3 4 5 6 7
|
void mkIndex( string names[21], char index[21] );
{
}
const int arraySize = 9;
/////......more material here
| |
Here is that same error repeated (the misplaces ";" following the "mkIndex" signature line).
If one removes that ";", we now have the "{" as the next important character after the ")" closing the signature for mkIndex, but we have a different problem.
It is quickly closed after a few comments in your text. That's the close of the function.
From "const int arraySize = 9;" forward, what we have is text outside of a function body (it was closed by the "}" earlier).
That makes the declarations of arraySize, readFile, myNumbers, kount, and the others, GLOBAL declarations of variables. That's actually legal, but very likely not what you intend. It appears these are supposed be inside the mkIndex function, and should therefore appear just after the opening "{" and before the close "}", along with the rest of that code which follows.
By the time the text reaches "inputFile.open("data.txt")" in your text the compiler is going to complain that functions can't be called outside of function bodies like this, which is solved by merely moving that code into a function as @dhayden demonstrates by moving that into main.
At this point I've merely narrated some of @dhayden changes, partly to explain a bit as to why, motivated by seeing repeated simple syntax mistakes.
Somewhere at this pint @dhayden wisely pauses to hand it back to you.
For that I pose a short discussion about your plan (both questions and suggestions).
As @dhayden was trying to make sense of these syntax errors, then paused, I pick up at this point from you:
The menu needs to loop until user is ready to exit
|
This becomes your outermost design point. The menu is first to be presented (after the copyrightinfo), and controls all else.
Naturally, THAT is what really belongs in main - or at least a driver for it. In typical animation loops (which this is, essentially), what we usually do is the really simple outline:
1 2 3 4 5 6 7 8
|
int main()
{
initialize();
while( menuLoop() );
// possibly a shutdown of resources when required, or just a goodbye
}
| |
This may seem so simple as to be useless, but it describes your entire, overall plan quite simply. There is initialization (your copyrightinfo display in this case), then a presumed looping of the menu. "menuLoop() is a proposed function that would return a bool, "true" for all actions except an exit request by the user, at which point the application closes. This repeats menuLoop until exit is requested.
Exactly as you've said.
The function of menuLoop is not a loop - that is looped from main. It is ONE PASS through the loop. That is, print the menu, take the input, take action on the input (if valid and not an exit), return true for all except exit condition (return false then).
Typically one takes in a number from the menu list, and performs a switch, where each case calls whatever function relates to that choice.
There's where you start. That's how you "hang everything else" on this "framework".
See how that fits your overall goals and continue posting your updated code and questions as you proceed.
From there we can discuss a few points in further exchange.
For example, what is in "data.txt" and what is in "inventory.txt", and what is "TenNumbers.txt"?
How do these files relate to the inventory you're loading and processing?