-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJumbled.cpp
More file actions
121 lines (77 loc) · 2.49 KB
/
Jumbled.cpp
File metadata and controls
121 lines (77 loc) · 2.49 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include<iostream>
#include<string>
#include<fstream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
const string WORD;
const int NUM_WORDS = 20;
const int MAX_GUESSES = 20;
string WORDS;
int points = 0;
string guess;
string filename;
char again;
char dummyvar;
//Get the filename from the user.
cout << "Enter the filename: ";
cin >> filename;
//Open the file
inputFile.open(test.txt());
//if the file successfully opened, process it.
if(inputFile)
{
while(inputFile >> WORDS)
{
}
//Close the file.
inputFile.close();
}
else
{
//Display an error message.
cout << "Error opening the file.\n";
}
do
{
srand(time(0));
int choice = (rand() % NUM_WORDS);
string theWord = WORDS [choice][WORD]; // word to guess
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.\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 == theWord)
{
cout << "\nThat's it! You guessed it!\n";
}//end if statement
else
{
cout << "Sorry, that's not it.";
}//end else statement
}//end for
cout << "\n\n\nWould You Like To Play Again? (y/n): ";
cin >> again;
}
while(again == 'y' || again == 'Y');
system("Pause");
system("cls");
cout << "Thanks for playing!";
return 0;
}//end main