is there a way to store points a person earnd on a game?
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream.h>
int main ()
{
srand((unsigned)time(0));
char name[9000];
int guess;
const int temp = 1 + (rand()%100);
int trys = 0;
int points = 9;
cout << "Guess what number I am thinking of between 1 and 100...\nto get points you have to guess it in 9 guesses : ";
cin >> guess;
while (guess != temp)
{
while (guess < temp)
{
cout << "The number is higher...Guess again : ";
cin >> guess;
trys++; if (trys == 8) {cout << "No points awarded";exit(1);}
}
while (guess > temp)
{
cout << "The number is lower...Guess again : ";
cin >> guess;
trys++; if (trys == 8) {cout << "No points awarded";exit(1);}
}
while (guess == temp)
{
cout << "You are correct \n and it only took "<<trys+1<<" try(s)...You get 10 points...\nEnter your name :";
cin >> name;
break;
}
ofstream fout;
fout.open("testfile.txt");
fout << "GOOD WORK " << name << " YOU GOT " << points++ << " POINTS";
fout.close();
}
return 0;
}
what i am trying to do is a person guess the correct answer then they enter their name and get 10 points and every time they answer correctly they get 10 more ect ect.....
is there a way to save it on a txt file and the txt file changes as the points increase....?