/* Hi Folks
I am really in trouble and very newbie in programming but hardworking. I
have coded an inventory program but the problem one function works again
when i exit from the program. Firstly, you add a new item then display all
items whic is second menu then you input 6 means exit program then program
will ask you again record a new item again. Please I need your help.
*/
I've made a couple of corrections to your code, it seems OK now. However, I
won't tell you the logic mistakes you did. I'll let you find your own
mistakes, comparing your code with mine.
I hope you'll see the syntax error in while ((ItemAdd=='Y') ||
(ItemAdd='y')). Did you compile this program? Didn't your compiler warn you
about this syntax error? And what compiler are you using?
Best wishes,
Engin Uysal
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>
#include <string>
using namespace std;
void MainMenu();
void NewRecord();
int DisplayItems();
#define LINE "____________________________________________________|"
#define TITLE " +++ INVENTORY MANAGEMENT SYSTEM +++ |"
#define BLANK " |"
#define INPUT " Please enter your selection :"
#define DOTEDLINE "----------------------------------------------------|"
#define COMMA " "
int main()
{
int selection;
MainMenu();
cout << INPUT;
cin >> selection;
if (( selection > 6) && (selection < 1))
{
cout << endl <<"You entered wrong number. Please enter"
<< "a number between (1 to 6) \n";
system ("PAUSE");
system("CLS"); // clean screen
main();
}
else
{
switch (selection)
{
case 1:cout << system("CLS"); NewRecord(); break;
case 2:cout << system("CLS"); DisplayItems(); break;
case 3:cout << "selected 3"<<endl; break;
case 4:cout << "selected 4"<<endl; break;
case 5:cout << "selected 5"<<endl; break;
case 6:cout<< BLANK <<endl<< BLANK <<endl<< LINE <<endl<<"Thank you for
using Inventory Management Software" <<endl<< LINE <<endl<< endl;
system("pause");
EXIT_SUCCESS;
break;
default : cout << "try again";
}
}
return 0;
}
//MAIN MENU FUNCTION
void MainMenu () {
int selection;
cout << LINE << endl;
cout << TITLE << endl;
cout << LINE << endl;
cout << BLANK << endl;
cout << " 1 - NEW ITEM RECORD |" << endl;
cout << " 2 - DISPLAY ALL ITEMS |" << endl;
cout << " 3 - SEARCH ITEM |" << endl;
cout << " 4 - UPDATION ITEM |" << endl;
cout << " 5 - REPORT ITEM STATUS |" << endl;
cout << " 6 - EXIT |" << endl;
cout << BLANK<<endl;
cout << DOTEDLINE<<endl;
}
// NEW RECORD ITEM
void NewRecord() {
char confirm='Y', ItemAdd='Y';
string ItemNumber, ItemName, ItemQ, ItemPrice;
ofstream ItemsFile("items.txt", ios::app);
if (!ItemsFile)
{
cerr << "Error opening output File";
}// if (!ItemsFile)
do
{
cout << "Enter Item Number : "; cin >> ItemNumber;
cout << "Enter Item Name : "; cin >> ItemName;
cout << "Enter Item Quantity : "; cin >> ItemQ;
cout << "Enter Price : "; cin >> ItemPrice;
cout << " Do you confirm entered item information? (Y-N)"; cin >> confirm;
if ((confirm=='Y') || (confirm=='y'))
{
ItemsFile << ItemNumber << COMMA << ItemName << COMMA
<< ItemQ << COMMA << ItemPrice << endl;
cout << "Item was succesfully added in Inventory" << endl;
system("Pause"); system("CLS");
}//if 1
else
{
cout << "Item was not added in Inventory"<<endl;
system("Pause"); system("CLS");
}//if 2
cout << "Would you like to add item again ? (Y-N)"; cin >> ItemAdd;
}while ((ItemAdd=='Y') || (ItemAdd=='y'));//while
ItemsFile.close();
main();
}//function
int DisplayItems () {
string reader;
ifstream DisplayFile("items.txt");
if (! DisplayFile)
{
cerr << "Error opening output file" << endl;
return -1;
}
while (! DisplayFile.eof())
{
getline (DisplayFile,reader);
cout << reader << endl;
}
DisplayFile.close();
system("Pause");
system("CLS");
main();
return 0;
}
[Non-text portions of this message have been removed]