Thread: Help!Counter...

  1. #1
    Unregistered
    Guest

    Help!Counter...

    Hi,

    My problem is of automatically generating an ID for a new competitor when the data is read from the input file .
    I tried to keep the counter ,but I think I am missing something...
    Pls help me out.......I just cant think anymore.....
    Thanks........

    Input file contains something like this:

    3 //latest ID is stored
    Jane Smith
    1
    M
    10
    12
    1980
    Anne Bloggs
    3
    F
    5
    12
    1970

    my code so far:
    Code:
    void adatabase(competitor database[],int number)
    {
        int i =0;
    	
            ifstream inputFile("records.txt", ios::in );
             if (inputFile.fail())
            {
               cout << "\n\t****** File could not be opened.              ******\n\n";
    		exit(0);
            }
    	
            while(!inputFile.eof() && number < DATABASESIZE)
            {
    			
           database[i].currID = atoi(readFileLine(inputFile).c_str());
    				
          database[i].competitorName= readFileLine(inputFile);
          database[i].ID = atoi(readFileLine(inputFile).c_str());
          database[i].compGender = atoi(readFileLine(inputFile).c_str());
        database[i].birthDate.day= atoi(readFileLine(inputFile).c_str());
        database[i].birthDate.month =atoi( readFileLine(inputFile).c_str());
       database[i].birthDate.year = atoi(readFileLine(inputFile).c_str());
    	
    	i++;
          }
    
    }
    
    void registerCompetitor(competitor database[],int number)
    {
            variable declaration ......
    
    if( number >= DATABASESIZE)
    {
    cout << "\n\n\t\t******** Database already full ********"
    				 
    	displayMainMenu();
    	getMenuOption(database,number);
    }
    else
    {
    compName = getCompetitorName();
    competitorName = validateCompetitorName(compName);
    cout<<"Your ID:"<<ID<<endl;	//  its show be read only and  display 4 as per InputFile//?????
    :
    :
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Location
    Fiji
    Posts
    212
    Im not to sure, but by the looks of it your ID counter is "i", so your should after you open the file, set "i" to the current id number, then go into your loop, and increment the id. Hope this helps. Like I said though I not sure, it's late at night.

  3. #3
    Unregistered
    Guest

    Sorry...

    Thanks for replying but still I didnt get u........Can u explain me..??
    thanks........

  4. #4
    Unregistered
    Guest

    Help Me

    Hi, plz help this novice out ..........I am struggling hard......
    thanks........

  5. #5
    Registered User
    Join Date
    Sep 2001
    Location
    Fiji
    Posts
    212
    First don't double post to get the thread higher on the board.

    Code:
    void adatabase(competitor database[],int number)
    {
        int i =0; //this is the id counter, right?
        //open file and do some stuff
        // assign the current id number here to "i"
        while(!inputFile.eof() && number < DATABASESIZE)
        {
             i++; //increment id counter
             database[i].currID = atoi(readFileLine(inputFile).c_str());

Popular pages Recent additions subscribe to a feed