Hello,
I have written a program were the user can enter information about a person. This information is saved into a file.
My only problem is displaying the data in the file. The ouput is all over the place and I can't figure out how to solve this. Any ideas/suggestions will be appreciated.
thanks
Code:
#include <fstream>
#include <iostream>
#include <iomanip>
#define cMax 100
using namespace std;
void crtNewClnt(char cName[], char cNum[], char cAddrs[], char cCity[], char cZip[]);
void dispClnts(char cName[], char cNum[], char cAddrs[], char cCity[], char cZip[]);
void clntMenu();
/***********************************************************************************
** This function will be called by user selection in the main.cpp file. *
** The main menu for Client Management will be displayed. *
***********************************************************************************/
int main()
{
int mSelec;
bool bDone = false;
do{
cout << "---------------------------" << endl;
cout << "---------------------------" << endl;
cout << "\n1. Client Management" << endl;
cout << "\nPlease enter your selection" << endl;
cin >> mSelec;
while (mSelec < 1 || mSelec > 5)
{
cout << "Please enter a correct selection between 1-5" << endl;
cin >> mSelec;
}
switch(mSelec)
{
case 1: clntMenu();
break;
case 5: cout << "You are now closing the program!" << endl;
bDone = true;
}
}while (!bDone);
return 0;
}
void clntMenu()
{
char cName[cMax];
char cNum[cMax];
char cAddrs[cMax];
char cCity[cMax];
char cZip[cMax];
int iSelec = 0;
system("cls");
cout << "*---------------------------*" << endl;
cout << setw(20) << " The DriftSpot" << endl;
cout << setw(22) << " Client Management" << endl;
cout << "*---------------------------*" << endl;
cout << "\n1. Create/add a new customer" << endl;
cout << "2. Display all customers" << endl;
cout << "\nPlease enter your selection [1-2]" << endl;
cin >> iSelec;
while (iSelec < 1 || iSelec > 6)
{
cout << "Please enter a correct selection. [1-6]" << endl;
cin >> iSelec;
}
switch(iSelec)
{
case 1:
crtNewClnt(cName,cNum,cAddrs,cCity,cZip);
break;
case 2:
// This calls out the function to display all items in inventory.
dispClnts(cName,cNum,cAddrs,cCity,cZip);
break;
}
system("cls");
}
void crtNewClnt(char cName[], char cNum[], char cAddrs[], char cCity[], char cZip[])
{
int xOut;
system("cls");
ofstream outputFile;
outputFile.open("clntInfo.txt", ios::app);
cout << "Please enter the name of the client:__";
cin.ignore();
cin.getline(cName, cMax);
cout << "Please enter the phone number of the client:__";
cin.getline(cNum, cMax);
cout << "Please enter the address of the client:__";
cin.getline(cAddrs, cMax);
cout << "Please enter the city:__";
cin.getline(cCity, cMax);
cout << "Please enter the zip code:__";
cin.getline(cZip, cMax);
outputFile << cName << setw(20) << cNum << setw(20) << cAddrs << setw(20) << cCity << setw(20) << cZip << endl;
outputFile.close();
cout << "\n************************************************";
cout << "\nYou have just added a new client to the data file!";
cout << "\n************************************************" << endl << endl;
cout << "Do you want to exit to the main menu now? 1 = [YES] , 0 = [NO]" << endl;
cin >> xOut;
while (xOut < 0 || xOut > 1)
{
cout << "Please enter a value between; 1 = [YES] , 0 = [NO]" << endl;
cin >> xOut;
}
}
void dispClnts(char cName[], char cNum[], char cAddrs[], char cCity[], char cZip[])
{
int xOut;
system("cls");
ifstream inputFile;
inputFile.open("clntInfo.txt");
if( !inputFile ) {
cout << "\n************************************************\n";
cout << "ERROR5: Could not open or locate InvItems.txt\n";
cout << " Make sure that the file exists.\n";
cout << "************************************************\n";
}
while(!inputFile.eof())
{
inputFile >> cName >> cNum >> cAddrs >> cCity >> cZip;
cout << cName << setw(20) << cNum << setw(20) << cAddrs << setw(20) << cCity << setw(20) << cZip << endl;
}
system("pause");
inputFile.close();
cout << "\nDo you want to exit to the main menu now? 1 = [YES] , 0 = [NO]" << endl;
cin >> xOut;
while (xOut < 0 || xOut > 1)
{
cout << "Please enter a value between; 1 = [YES] , 0 = [NO]" << endl;
cin >> xOut;
}
system("cls");
}