I'm encountering some problem with program I write here. The program is able compiled without error. But when I try to call "Add Function" and execute system to capture data, it goes wrong. It only allow insert value for name but skip the rest, and program run keeps on run in loops. I check through but find not problem. Can anyone help me??
#include <iostream>
#include <list>
#include <string>
#include <fstream> //open the file for input/output
#include <iomanip>
#include <stdio.h>
using namespace std;
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/////// Add Record Function ///////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
struct RunnerRec // Structure to define variables in the Student Records.
{
char Name[30]; // Nameof the runner.
char BibNum; // Runner's ID.
char PhoneNum[10]; // Phone number of the runner
char Gender; // Gender of the runner
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/////// Add Record Function ///////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
if (!file) //Validate RunnerRecords.txt is valid file
{
cerr << "file open error!" << endl;
return ;
}
list < RunnerRec > Runlist;
RunnerRec run;
int RunNum ; // Variable to count how many records insert each time
cout << "Please enter how many records you wish to insert:" <<endl;
cin >> RunNum;
switch(input)
{
case 1: Add();
break;
case 2: Change();
break;
case 3: Delete();
break;
case 4: Search();
break;
case 5: DisplayAll();
break;
case 6: Quit ();
break;
default: cout << "You did not enter a correct choice!!" << endl;
break;
}
}while(input != 6);
I do not think this is the problem, but inside that if statement block where you check if the file has been open there should be something that closes the file for good programming practice.