This is pretty good so far. For a new feature of a program, consider isolating it into its own function, completely commenting everything out that you have so far until the function works. You can do this easily with
#if 0
. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <string>
using namespace std;
// Returns index of most sold item in a 5-item array
int MostSold(int sold_items[5])
{
// TODO: write some logic to do this!
return 0;
}
int main()
{
#if 0
// Everything you have in here so far
#endif
string item_names[] = {"Markers", "Paper", "Notebooks", "Candy", "Milk"};
int num_sold[] = { 1, 5, 13, 6, 7};
int index = MostSold(num_sold);
cout << "Most sold: "<< item_names[index] << "("<<
num_sold[index] << ")\n";
}
|
Current output:
Stylistic Notes:
-- You may find it easier on the eyes to set your editor to "Convert tabs to spaces", and
-- Set the number of spaces to 4. People have different preferences, but this is a common value I see mentioned, especially for C-family languages. It's easier to copy over to emails, forum posts, etc.
-- For legacy reasons, there are a lot of people who like to keep their line length to about 80 columns. These days, something like 100 columns probably doesn't hurt, /shrug, and yeah, a lot of modern editors have nice word-wrapping support, but sometimes you'll run into places where long lines don't look so good. To help keep column length lower, note that cout parts can be chained together like so (and you may prefer for visual reasons to write endl instead of \n to mark the end of a line):
1 2 3 4 5 6 7
|
cout << "--------- MAIN MENU ---------" << endl << endl <<
"Please pick from an option below:" << endl <<
"1: Enter new items" << endl <<
"2: Change item prices" << endl <<
"3: Input sold items" << endl <<
"4: All items and prices" << endl <<
"5: Receipt for previous items sold" << endl;
|