Problem in classes

Hey
i am making a multiple quiz program.
so everything is working fine, except for the part where i'm trying to add a highscore for each user which is being stored in a binary file. I have added a sample of the program containing the error. This isn't the actual program, which is very long.
please if you could help me :)

PS if you would like to look at the real code, i can post that as well

class user //The collection of all info pertaining to the users
{
char user_id[50];


public:

int hscore1;

user()
{
strcpy(user_id,"NULL");
hscore=0;

}

void user_create(char id[50])
{
strcpy(user_id,id);
}

char* get_id()
{
return user_id;
}

};


int main()
{
char id[50];
cin.getline(id,50);
int scr;
cin >> scr;
cin.ignore();
fstream u_db("U.dat",ios::binary|ios::in|ios::out);

user u;
while(u_db.read((char*)&u,sizeof(u)))
{
if(!strcmpi(u.get_id(),user_id))
{
if(u.hscore<=scr)
{
u.hscore1=scr;
u_db.write((char*)&u,sizeof(u));
}
cout << "\nYour high score is: " << u.hscore;
}
}
> so everything is working fine, except for the part where i'm trying to add a highscore
you need to be a little more descriptive.
┬┐what's the issue with the `highscore'?
- it is not as high as it should
- it is pure garbage
- it has disappeared
- it erased the file
- it blow your computer

> I have added a sample of the program containing the error. This isn't the actual program
good, however when you do that make sure that your snip does reproduce your issue.
as it is, your code does not even compile, missing a closing brace and some variables declarations (user_id, user::hscore is user::hscore1)

Also, given that you are using a file, it would be nice if you provide an example of it.


And use code tags when posting code
Topic archived. No new replies allowed.