So this program records your inputed stats after a game, it saves them to a textfile everytime you input them. However near the end I am having trouble with making the program read the textfile once the user inputs "yes" to the answer
"Do you wish to view your previous score?"
I wonder if its a small fix or a complete re-write of that section :D
Thanks ahead
#include <iostream>
#include <string>
#include <fstream>
#include <Windows.h>
usingnamespace std;
int main()
{
double kills;
double deaths;
double kdratio;
double rounds;
double killsperround;
double deathsperround;
string mapname;
HANDLE h = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute(h, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
cout << "How many rounds did you play this game? (Please enter correct number to work out Kills/Deaths per round" << endl;
cin >> rounds;
cout << "You played " << rounds << " rounds" << endl;
cout << "Please enter the amount of kills you got this game " << endl;
cin >> kills;
cout << "You got " << kills << " kills" << endl;
cout << "Please enter how many times you died this game " << endl;
cin >> deaths;
cout << "You died " << deaths << " times" << endl;
kdratio = kills / deaths;
cout << "Your KD Ratio for this game is " << kdratio << endl;
cout << "Please enter the map you have played" << endl;
cin >> mapname;
cout << "You played " << mapname << endl;
killsperround = kills / rounds;
deathsperround = deaths / rounds;
cout << "You got " << kills << " kills and " << deaths << " deaths, you played on " << mapname << " and got a KD Ratio of " << kdratio << endl;
ofstream scores;
cout << "Your Kills per round were " << killsperround << " and your deaths per round were " << deathsperround << endl;
if(kdratio>1){
HANDLE h = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute(h, FOREGROUND_GREEN | FOREGROUND_INTENSITY);
cout << "Your KDA was greater than 1 this game, congratulations! Keep it up" << endl;
}else{
HANDLE h = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY);
cout << "Your KDA was less than 1, better luck next time!" << endl;
}
HANDLE g = GetStdHandle( STD_OUTPUT_HANDLE );
SetConsoleTextAttribute(g, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
scores.open("scoresandmap.txt", ios::app);
scores << "You got " << kills << " kills and " << deaths << " deaths you played on " << mapname << " and got a KD Ratio of " << kdratio << endl;
scores << "Your Kills per round were " << killsperround << " and your deaths per round were " << deathsperround << endl;
scores.close();
string answer;
cout << "Do you wish to view your previous scores? (Yes/No)" << endl;
cin >> answer;
if(answer == "yes"){
ifstream inFile;
inFile.open("scoresandmap.txt");
//Check for Error
if (inFile.fail()) {
cerr << "Error finding text file" << endl;
exit(1);
}
}else{
exit(1);}
}