Line 9: Why is this called loop()? It doesn't loop. A better name is menu().
Lines 9-11: Your argument and your local variables are not used in the function. Why are they there?
Line 28: You should do the following:
1 2
|
cin >> choice2;
return choice2;
|
Line 37,38: item, price and i are local variables. Their values are lost when you exit the function.
Line 40: Why are you testing for 5? Your arrays can hold 10 items. The best way to ensure these are consistent is to use a
constexpr
to define the size of your array. If you want to change the maximum size of the inventory, you only need to make the change in one place.
1 2 3 4 5 6
|
constexpr MaxInventory = 10;
...
char item[MaxInventory][20];
int price[MaxInventory];
...
if (i == MaxInventory)
|
Line 57, 77, 107: You output the return value of loop(), but loop() has no return statement.
Line 60: You call itemloop() recusrsively. This is a poor dsesign. You should use a loop.
Line 101: If choice3 is Y, simply
return;
Line 107: You call list() recursively. Again, a poor design. Use a loop.
Lines 76,80,83,87,90,93: You reference the value of i, but i is not defined in your function.
Lines 76-95: You should use a loop here. At this point, i contains the number of elements in the inventory.
1 2
|
for (int j=0; j<i; j++)
cout << "Item and price is: " << item[j] << " " << price[j]<< "\n";
|
Line 122: You output the return value of itemloop(), but itemloop() has no return value.
Lines 120, 124: This is a perfect place for a switch statement.
1 2 3 4 5 6 7
|
choice = menu();
switch (choice)
{
case 1: itemloop(); break;
case 2: list (); break;
default: // do something
}
|