Hi there. I'm trying to make a program that loads a value from a file (starting from 0 ) and adds a number each time.
i.e. I have a file "data.log" that contains 0 , after the first run I add 100 so now it contains 100, then I add 50 , and it contains 150 and so on.
The problem is: 4 lines before the endCode:#include <fstream> #include <iostream> #include <iomanip> using namespace std; int main() { int MyScore = 0 , i = 0; char Temp = '0', c = '0'; fstream my_file; my_file.open("data.log", ios::out | ios::in); if( my_file) cout <<"found"<<endl; else cout <<"not found"<<endl; // LOADING FROM FILE my_file.get(Temp); cout<<setw(40)<<"Simple Program"<<endl; for(i=0;i<80;i++) cout<<'-'; gputs("How much completed?:\na. 1/3\nb. 1/2\nc. 1\n ans = "); c = cin.get(); switch (c) { case 'a': MyScore += 50; break; case 'b': MyScore += 75; break; case 'c': MyScore +=100; break; default : break; } cout<<endl<<endl; MyScore += Temp - '0'; my_file<<"My Score is :"<<MyScore<<endl; my_file.put(MyScore); my_file.close(); cin.get(); return EXIT_SUCCESS; }
doesn't work as it shouldCode:my_file.put(MyScore);
Do you have any idea why?



LinkBack URL
About LinkBacks


