C++ Help

I have made a somewhat beginner/mid level High Low game
what i would like to do is implement a high score…well for lack of better termss thingy
for example:

It took you 6 guesses
That beat the last high score of…
get the idea
thank you

attached is the source code

If I was at home I could give you a small script that allows you to open up .txt file and sort through it to display highscores or save them…

Unfortunately… I can’t remember the code for the life of me now… I haven’t opened up Borland’s C++ in nearly 8 months… lol

Later On Man… Will get back to you with the info…


ifstream file("highscores.txt");
int scores[100],i=0;
while(file>>scores[i++]);

int tmp;
for(int j=0;j<i-1;j++)
  for(int k=j+1;k<i;k++)
    if(scores[j]<scores[k])
      {
          tmp = scores[j];
          scores[j] = scores[k];
          scores[k] = tmp;
       } //sorting from higher to lower

and then you can cout the entire array in a for()

file.close();

–i don’t know if this code workx, cause i’ve made it up just right now (haven’t tested)
–highscores.txt should contain the scores separated by a new line (’
') or by space

i forgot to mention, in order to use the file streams in c++, u must include the fstream.h header…

oh, and to write in a file u use the ‘ofstream’ object class, like this:

ofstream file(“highscores”,ios::app);
//i’ve used ios::app, cause i want to write information at the end of the file
file<<’
'<<variable;
file.close();

remember not to use ifstream file() and then declare ofstream file() --i mean, don’t use the same name files for reading and writing, cause it will give you a compilation error

anyway, u can also use the file.open() command after you’ve declared it’s type, which may be ‘fstream’… what i mean is you can do this:

fstream file;
file.open(“highscores”,ios::in); //open for reading
//procces file
file.close();
file.open(“highscores”,ios::out | ios::app); //open at the end of file for writing
file.close();

//don’t forget to use the .close() fstream class member function

■■■■… forgot to put ‘PHP’ and ‘/PHP’ at the code and it’s now messed up, cause the browser thinks what i wrote is html code :confused: …any moderator here to help me?

It’s something like that…

I’ll check that out later tonight or tomorrow to see if it’s correct :slight_smile:

Peace

ok i figured it out
i just made two new variables for low and high score
than i just used some nested ifs

ok heres the scoop
ive been working on an rpg for some time and finall today i finished and when i finished i only got 3 errors
that is mega w00t
well i fixed the errors and this is what it gave me

--------------------Configuration: ProjectGenocide - Win32 Debug--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/ProjectGenocide.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ProjectGenocide.exe - 2 error(s), 0 warning(s)

any ideas
ill attach the code

the linking error appeared because you’ve made a workspace for win32 windows applications; the function WinMain() is for windows what main() is for ms-dos console applications

i assume you are using visual studio… if so, create another workspace specifying it will be a console application type; copy all the code you’ve written and compile again; success is guaranteed :slight_smile:

oh, and ‘ProjectGenocide’ … what a name for a c++ project :slight_smile:

peace all of you out there

oh thanks

i wish i knew **** like you do

which one of those do i choose

attahcment

get ws xp ;PP [i know it has a lot of backdoors put there by microsoft, but it’s the best]

lol
i fixed it
■■■■ i fel really stupid like wehn it ran all my loops were ****ed
the first loop was messed up and wouldnt take the correct input, so inturn that messed up all my other loops and damage counters :confused: back to the old drawing board it looks like:hair: