I get the output:
Martin's Hardware
-----------------
Part No. Price Count Remaining
-858993460 -858993460 -858993460
-858993460 -858993460 -858993460
-858993460 -858993460 -858993460
-858993460 -858993460 -858993460
-858993460 -858993460 -858993460
DataMaster options:
1. Add an Item.
2. Print Report.
3. Exit Program.
Enter 1, 2 or 3 to select option-->
Seems that the array is getting input into but the print output is all "blamo'ed" please help me.
*************************************************************/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int menu();
void addItem(int[],int[],int[], int, int);
void printReport(int[],int[],int[], int, int);
int main()
{
const int size = 5;
int partNumber[size];
int price[size];
int remaining[size];
int count = 0;
int addItem_option = 1,
printReport_option = 2,
exit_option = 3,
option;
option = menu();
if (option == 1)
addItem(partNumber,price,remaining, count, size);
if (option == 2)
printReport(partNumber,price,remaining, count, size);
else
exit(0);
system("pause");
return 0;
}
/************************* menu **************************
NAME:menu
PURPOSE: Select options
CALLED BY: main()
INPUT: int partNumber, int price, int remaining, int count, int size.
OUTPUT: int option
****************************************************************************/
int menu()
{
int option;
while ((cin.fail()) || (option < 1) || (option > 3))
{
cin.clear();
cin.ignore(1000,'\n'); // Ignore up to 1000 characters input
cout << "\n\n\tInput failure, you must enter a #: 1,2 or 3 -->";
cin >> option;
}
system("cls");
return option;
}
/************************* addItem **************************
NAME:addItem
PURPOSE: input values into array
CALLED BY: main
INPUT: int partNumber, int price, int remaining, int count, int size.
OUTPUT: none
****************************************************************************/
void addItem(int partNumber[],int price[], int remaining[], int count,int size)
{
for (count = 0; count < size; count++)
{
cout << "Enter the part # of the item: ";
cin >> partNumber[count];
cout << "\nEnter the price of the item: ";
cin >> price[count];
cout << "\nEnter quantity remaining: ";
cin >> remaining[count];
system("cls");
main();
}
}
/************************* printRecipt **************************/
NAME:printRecipt
PURPOSE: Select options
CALLED BY: (what is callING function?)
INPUT: (parameters function receives)
OUTPUT: (values that are returned)
****************************************************************************/
void printReport(int partNumber[],int price[], int remaining[], int count, int size)
{
You're getting garbage printed out because you're recursively calling main() from within addItem()/printReport(). When you type in option 2, it prints the values which are currently on the stack. Instead, you should be calling menu() and addItem()/printReport() in a loop until the user decides to quit.