FILE STREAM CODES...must see...

guyss need help or codes for this...to save into a text file the score and the correct guess...thankss..this code is working..maybe it is good in file streaming...need codes..hehe :D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	enum fields {WORD, HINT, NUM_FIELDS};
	const int NUM_WORDS = 6;
	const int MAX_GUESSES = 5;
	const string WORDS[NUM_WORDS][NUM_FIELDS] =
	{
	{"computer", "Do you feel you're banging your head against something?"},
	{"keyboard", "These might help you see the answer."},
	{"mouse", "Going slowly, is it?"},
	{"speaker", "Keep at it."},
	{"printer", "It's what the game is all about."},
	{"harddrive", "Now you know."},
	};

	string guess;
	int points = 0;
	char another;


	do
	{
		system("cls");
		srand(time(0));
		int choice = (rand() % NUM_WORDS);
		string theWord = WORDS[choice][WORD]; // word to guess
		string theHint = WORDS[choice][HINT]; // hint for word

		string jumble = theWord; // jumbled version of word
		int length = jumble.size();

		for (int i=0; i<length; ++i)
		{
			int index1 = (rand() % length);
			int index2 = (rand() % length);
			char temp = jumble[index1];
			jumble[index1] = jumble[index2];
			jumble[index2] = temp;
		}
		cout << "\t\t\tWelcome to Word Jumble!\n\n";
		cout << "Unscramble the letters to make a word FOOL.\n";
		cout << "[hint] all about computer..good luck...BITCHH!!!\n";
		cout << "Enter 'hint' for a hint.\n";
		cout << "Enter 'quit' to quit the game.\n\n";
		cout << "The jumble is: " << jumble;
	
		for(int nIndex = 0; nIndex < MAX_GUESSES; nIndex++)
		{
			cout << "\n\nGuess " << nIndex+1 << ": ";
			cin >> guess;

			if (guess == "hint")
			{
				cout << theHint;
				points--; //subtract 1 point 
			}//end if
			else if (guess == theWord)
			{
				cout << "\nThat's it! You guessed it!\n";
				points += guess.size(); //points = # of letters in word
				break;
			}//end else if
			else
			{
				cout << "Sorry, that's not it.";
			}//end else
		}//end for
		cout << "\n\nYour Total Points Are: " << points;
		cout << "\n\n\nWould You Like To Play Again? (y/n): ";
		cin  >> another;
	}while(another == 'y' || another == 'Y');

	system("cls");
	cout << "Thanks for playing!";

	return 0;
}//end main
Topic archived. No new replies allowed.