I've never acctuelly had this problem before, so I was wondering why the following program always closes right after you reach the end of the program (outputing the stored data).
Here is the code so far:
The book I'm reading right now that I got it from, mentioned it in the first chapter, but since I never experieinced this happening in the first chapter, but never gave a way to solve it. Also, I had never had this problem up until now. Can anybody explain how to stop this from happening?Code:#include <iostream.h> #include <stdio.h> #include <string.h> //class class NameDataSet { public: char firstName[128]; char lastName[128]; int ssNumber; }; //getdata function will retrieve info from user in consol int getData(NameDataSet& nds) { std::cout<<"\nEnter your first name:\n"; std::cin>>nds.firstName; if ((strcmp(nds.firstName, "exit") == 0) || (strcmp(nds.firstName, "EXIT") == 0)) { return 0; } std::cout<<"\nEnter your last name:\n"; std::cin>>nds.lastName; std::cout<<"\nEnter credit card number:\n"; std::cin>>nds.ssNumber; return 1; } //display data will display all data in the database void displayData(NameDataSet& nds) { std::cout<<"Your name(s):\n" << nds.firstName << " " << nds.lastName << "\n"; std::cout<<"Your creditcard number(s):\n" << nds.ssNumber << "\n"; } int main(int nArg, char* pszArgs[]) { NameDataSet nds[25]; std::cout<<"Read name/credit card information\n" << "Enter 'exit' for first name to exit\n"; int index=0; while (getData(nds[index])) { index++; } std::cout<<"\nEntries\n"; for (int i = 0; i < index; i++) { displayData(nds[i]); } return 0; }



LinkBack URL
About LinkBacks



It recommends alternate methods, due to security vulnerabilities inherent in the system() call - anyone can write a program, name it 'pause.exe' or 'pause.com', and replace the one that came with your computer.