Thursday, July 30, 2009

How much experience with C++ would you need to save High Scores? Also, can you help me?!?

I have a simple program. A Random Number Generator makes a number, from 1,000, and the user guesses it, and continues to guess it until they get it right, and it records the guess taken. I want to know how I could save the amount of guesses in a high score type way, how much experience I would need to do that, and if I could do it by saving the lowest amount of guesses. Yeah, I'm a newb.





Also, I'm using Dev-C++ for my compiler.

How much experience with C++ would you need to save High Scores? Also, can you help me?!?
You can create an output stream file object and write the names and scores in a file...





for recording a score:


If you have a loop for guessing, include an incremental variable in the loop, such as:





score++;


So that every time you ask, it increments the score by 1.











for saving:





#include %26lt;fstream%26gt;


#include %26lt;string%26gt;





ofstream myfile;


myfile.open ("example.txt");


cout %26lt;%26lt; "What is your name?";


string name;


cin %26gt;%26gt; name;


myfile %26lt;%26lt; name %26lt;%26lt; score;


myfile.close();











Include something like that in your code :)

floral bouquets

No comments:

Post a Comment