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
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 …any moderator here to help me?
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
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
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 back to the old drawing board it looks like:hair: