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. 
   
  INVENTORY MANAGEMENT
   
  #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 < 7) && (selection > 0))
    
    {
                 
                 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("exit"); break;
                      default : cout << "try again";
                      
                 }
                      
    }
                      else
    {          
                       cout << endl <<"You entered wrong number. Please enter"
                            << "a number between (1 to 6) \n"; 
                       cin.get(); 
                       system ("PAUSE");
                       system("CLS"); // clean screen
                       main();
    }     
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
  //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) 
                     
                     while ((ItemAdd=='Y') || (ItemAdd='y')) 
                               {
                             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 
succesfully added in Inventory" << endl;
                                                        system("Pause"); 
system("CLS"); main();
                                                    }//if 1 
                                                    
                                                    else
                                                    
                                                    {
                                                        cout << "Item did not 
add in Inventory"<<endl;
                                                        system("Pause"); 
system("CLS"); main();
                                                    }//if 2
                                                    
//cout << "Would you like to add item again ? (Y-N)"; cin >> ItemAdd;
                             }//while
      ItemsFile.close();
    system ("exit");
      }//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]

Reply via email to