Hello mcclit,
After getting the program to run this is what I saw:
Your program starts with:
spend
show
amount >=
save file
help
exit
|
This is asking much of the user to enter the correct choice. You will find that a user will break your program without even trying when they enter something like "Show" or SHOW" because the had "Caps Lock" turned on and you did not account for this. Not to mention the spelling mistakes that can happen. This is to much to ask of the user.
I think you will find this better:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int choice;
std::cout << std::fixed << std::showpoint << std::setprecision(2);
cout
<< "\n 1. Spend"
<< "\n 2. Show"
<< "\n 3. Amount >="
<< "\n 4. Save file"
<< "\n 5. Help"
<< "\n 6. Exit\n"
<< " Enter choice: ";
cin >> choice;
|
1. Spend
2. Show
3. Amount >=
4. Save file
5. Help
6. Exit
Enter choice: |
I do not know what you can use, but I followed the input here with a "switch" which calls the necessary functions. If you are not up to functions you can put the code in the case statements. And if you are not familiar with a switch you can use if/else if statements with the final else statement to catch anything that is invalid.
It would also be a good idea to follow the menu choice with some kind of verification to know that only a valid choice was entered. This can also be handled in the "default' case section or the final "else" of the "if/else" if statements.
For now I created two functions for the menu choices. One "Show()" and the other "Report()" although this should have a better name to describe what it does.
In the functions I started with the same idea that
coder777 has suggested. If you are not familiar with or able to use a range base for loop a regular for loop will work.
Just for fun I added a sort routine, but that will take some work to set up to use the third parameter of "std::sort".
After getting the program to run I realized what the "else if" on line 36 is for. By its self you can not have just an "else if" you would need at least:
1 2 3 4 5 6
|
if (choice == 1)
;
else if(...)
{
// ...
}
|
The alternative with the switch is that you can leave out the case statements that you are not ready for yet.
Hope that helps,
Andy