PDA

View Full Version : C++ Help



kaotic
January 24th, 2003, 08:40 PM
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

Marz
January 25th, 2003, 09:23 AM
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..

c0ldfusion
January 25th, 2003, 04:16 PM
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 ('\n') or by space

c0ldfusion
January 25th, 2003, 04:23 PM
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<<'\n'<<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

c0ldfusion
January 25th, 2003, 04:25 PM
damn... 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?

Marz
January 25th, 2003, 05:32 PM
It's something like that....

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

Peace

kaotic
January 25th, 2003, 06:21 PM
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

c0ldfusion
January 26th, 2003, 03:42 PM
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 :)

c0ldfusion
January 26th, 2003, 03:43 PM
oh, and 'ProjectGenocide' ... what a name for a c++ project :)

peace all of you out there

kaotic
January 26th, 2003, 05:04 PM
oh thanks

i wish i knew **** like you do

which one of those do i choose

kaotic
January 26th, 2003, 05:10 PM
attahcment

c0ldfusion
January 29th, 2003, 03:48 PM
get ws xp ;PP [i know it has a lot of backdoors put there by microsoft, but it's the best]

kaotic
January 29th, 2003, 06:32 PM
lol
i fixed it
damn 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: