### save to a text file...plzz read..

guyyss need your code help to save
 ``12`` ``````cout << "You've made 3 mistakes ! Game is now over !" << endl; cout << "You had " << correctGuesses << " correct guesses before the game was over" << endl;``````
this info into a text file...

example of a guessing game code...
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263`` ``````#include #include using namespace std; int main() { cout << "This is a very simple number guessing game. Each time you will be given a number of the range 0-10." << endl; cout << "The objective of the game is to guess whether the next number is going to be higher or not. As simple as that." << endl; cout << "You have the ability to make no more than 3 mistakes before you lose, so guess wisely." << endl << endl; cout << "You are starting with number 5. Is the next number higher(write H) or lower(write L) ?" << endl; int mistakes = 0; int correctGuesses; int prevNum = 5, nextNum; char choice; do { srand ( time(NULL) ); do nextNum = rand() % 11; while (nextNum == prevNum); cin >> choice; if (choice == 'H') { if (prevNum < nextNum) { cout << "Correct ! The new number is " << nextNum << endl; correctGuesses++; } else if (prevNum > nextNum) { cout << "Wrong, you made a mistake ! The new number is " << nextNum << endl; mistakes++; } } if (choice == 'L') { if (prevNum > nextNum) { cout << "Correct ! The new number is " << nextNum << endl; correctGuesses++; } else if (prevNum < nextNum) { cout << "Wrong, you made a mistake ! The new number is " << nextNum << endl; mistakes++; } } prevNum = nextNum; } while(mistakes < 3); cout << "You've made 3 mistakes ! Game is now over !" << endl; cout << "You had " << correctGuesses << " correct guesses before the game was over" << endl; return 0; }``````
Last edited on
http://cplusplus.com/reference/fstream/ofstream/
Look at example on the bottom of page: http://cplusplus.com/reference/fstream/ofstream/open/
You can use operator << with filestream as with ostream (cout)
Topic archived. No new replies allowed.