Okay, so as a side project Im making a program that will keep track of standings in a league. It keeps track of the wins/loss/tiebreaker of every player and saves that to a text file. The program also has an option to display the standings.
What im currently stuck on is updating the stats. So lets say I input week 1 stats for user one. His record is 10-5-2, that record gets saved to a text file. Then lets say week 2 he goes 11-4-2. I would like to be able to have the program add up his total record. So it would read the 10-5-2 from week 1, and add the 11-4-2 to it. Then output that total to the file (21-9-4)
// Predictions calculator and refresher on C++
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int main ()
{
string name = "";
int a;
int b = 3;
int loss;
int wins;
int tb;
string name2 = "";
int loss2;
int wins2;
int tb2;
cout << " Welcome To the 2011 Football Predictions Calculator. \n" << " \n" << " \n";
cout << "What would you like to do? \n \n";
cout << "To edit standings press 1. To view standings press 5.\n";
cin >> a;
cout << "\n";
if(a < 3)
{
cout << "What is the first users name? \n";
cin >> name;
cout << "What is " << name << "'s amount of wins \n";
cin >> wins;
cout << "What is " << name << "'s amount of losses? \n";
cin >> loss;
cout << "What is " << name << "'s tie breaker score? \n";
cin >> tb;
cout << name << " 's record is " << wins << " - " << loss << " - " << tb << "\n";
ofstream myfile;
myfile.open ("standing.txt");
myfile << "2011 Football Prediction Standings\n" << name << " " << wins << " - " << loss << " - " << tb << " \n";
cout << "What is the second users name? \n";
cin >> name2;
cout << "What is " << name2 << "'s amount of wins \n";
cin >> wins2;
cout << "What is " << name2 << "'s amount of losses? \n";
cin >> loss2;
cout << "What is " << name2 << "'s tie breaker score? \n";
cin >> tb2;
cout << name2 << " 's record is " << wins2 << " - " << loss2 << " - " << tb2 << "\n \n \n \n \n";
myfile << name2 << " " << wins2 << " - " << loss2 << " - " << tb2 << " \n";
myfile.close();
;}
else
{
// std::cout << "Press ENTER to continue...";
//std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
//Reading from file and outputting
int length;
char * buffer;
ifstream is;
is.open ("standing.txt", ios::binary );
// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);
// allocate memory:
buffer = newchar [length];
// read data as a block:
is.read (buffer,length);
is.close();
cout.write (buffer,length);
delete[] buffer;
;}
system("pause");
return 0;
}
I guess my question is how do I go about reading the text file, getting the records as an integer. Once I can declare the records as an integer I know how to get the program to do the math and re-write to the .txt file.
Im pretty sure im going to have to rewrite the majority of the program to do it, but im pretty lost, and blatantly new to C++.
Thanks