# C++ Help

**URL:** <https://forum.kirupa.com/t/c-help/12002>\
**Category:** random\
**Created:** [January 25, 2003, 1:40am UTC](https://forum.kirupa.com/t/c-help/12002 "2003-01-25T01:40:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaotic](https://avatars.discourse-cdn.com/v4/letter/k/c77e96/32.png) [@kaotic](https://forum.kirupa.com/u/kaotic)\
**Post date:** [January 25, 2003, 1:40am UTC](https://forum.kirupa.com/t/c-help/12002/1 "2003-01-25T01:40:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 2:23pm UTC](https://forum.kirupa.com/t/c-help/12002/2 "2003-01-25T14:23:35Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 9:16pm UTC](https://forum.kirupa.com/t/c-help/12002/3 "2003-01-25T21:16:48Z")

</div>

```php

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 9:23pm UTC](https://forum.kirupa.com/t/c-help/12002/4 "2003-01-25T21:23:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 9:25pm UTC](https://forum.kirupa.com/t/c-help/12002/5 "2003-01-25T21:25:43Z")

</div>

■■■■… 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?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 10:32pm UTC](https://forum.kirupa.com/t/c-help/12002/6 "2003-01-25T22:32:18Z")

</div>

It’s something like that…

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

Peace

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 25, 2003, 11:21pm UTC](https://forum.kirupa.com/t/c-help/12002/7 "2003-01-25T23:21:35Z")

</div>

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

```php
--------------------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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 8:42pm UTC](https://forum.kirupa.com/t/c-help/12002/8 "2003-01-26T20:42:03Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 8:43pm UTC](https://forum.kirupa.com/t/c-help/12002/9 "2003-01-26T20:43:00Z")

</div>

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

peace all of you out there

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 10:04pm UTC](https://forum.kirupa.com/t/c-help/12002/10 "2003-01-26T22:04:41Z")

</div>

oh thanks

i wish i knew \*\*\*\* like you do

which one of those do i choose

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 26, 2003, 10:10pm UTC](https://forum.kirupa.com/t/c-help/12002/11 "2003-01-26T22:10:48Z")

</div>

attahcment

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2003, 8:48pm UTC](https://forum.kirupa.com/t/c-help/12002/12 "2003-01-29T20:48:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 29, 2003, 11:32pm UTC](https://forum.kirupa.com/t/c-help/12002/13 "2003-01-29T23:32:27Z")

</div>

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:
