heeeeelp!!!

im a beginner in C++ and i need my questions in the program to be randomized and i dont know what im going to do! could someone good at it help me please! my project is on tuesday =_= ... and im out of time! my teacher gave us only 5days to complete it >_< ... and i dunno what to do~

#include<iostream>
#include<string>

using namespace std;
main()
{
cout<<"***************GUESS MY WORD GAME*************** \n";

char ans;
cout<<endl;
do
{
cout<< "PRESS Y to start! ^_^\n";

cout<< "\n\n Guess my SECRET word or face my wrath!!]\nINSTRUCTION: You can PRESS H for the given hints later when the game starts\n";

cout<<" THE LOOP WILL NOT STOP UNTIL YOU PRESS Y ........XD \n ";
cout<<"ENTER or DIE! :> ";
cin >> ans;

}
while((ans !='Y')&&(ans !='y')); //prompt the user to PRESS Y button to start! if the user PRESS any key except the Y button... the program will appear again and again until the Y button is PRESSED

system("cls");

{
string SECRET_WORD = "hair"; // this is the word that the user is challanged to guess...

string SECRET_GUESS;// the users guess


cout << "its in you everywhere!" << endl;
char H;
cout<<endl;
cout<<"Press H for Hint(X to cancel it)"<<endl;
cin>>H;
cout<<endl;
if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
{
cout<<"You touch it everytime you scratch your head"<<endl;
cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
cout<<endl;
cin >> SECRET_GUESS;
cout<<endl;
if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
else
cout << "wrong answer! please try again!" ;//wrong answer

cout<<endl;
system("pause");}
if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
{
cout<<endl;
cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
cin >> SECRET_GUESS;
if(SECRET_WORD == SECRET_GUESS)// likewise
cout << "Correct the secret word was " << SECRET_WORD << endl;
else// likewise
cout << "wrong answer! please try again!" << endl;
}

system("pause");
{cout<<"invalid command! please read the instruction once more!";

}
}
system("cls");
{
string SECRET_WORD = "medicine";
string SECRET_GUESS;// the users guess


cout << "You need it everytime you got sick !" << endl;
char H;
cout<<endl;
cout<<"Press H for Hint(X to cancel it)"<<endl;
cin>>H;
cout<<endl;
if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
{
cout<<" it makes you better! "<<endl;
cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
cout<<endl;
cin >> SECRET_GUESS;
cout<<endl;
if(SECRET_WORD == SECRET_GUESS)
cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
else
cout << "wrong answer! please try again!" ;//wrong answer

cout<<endl;
system("pause");}
if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
{
cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
cin >> SECRET_GUESS;
if(SECRET_WORD == SECRET_GUESS)// likewise
cout << "Correct the secret word was " << SECRET_WORD << endl;
else// likewise
cout << "wrong answer! please try again!" << endl;
system("pause");}
}
system("cls");
{
string SECRET_WORD = "hair"; // this is the word that the user is challanged to guess...

string SECRET_GUESS;// the users guess
cout << "its in you everywhere!" << endl;
char H;
cout<<endl;
cout<<"Press H for Hint(X to cancel it)"<<endl;
cin>>H;
cout<<endl;
if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
{
cout<<"You touch it everytime you scratch your head"<<endl;
cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
cout<<endl;
cin >> SECRET_GUESS;
cout<<endl;
if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
else
cout << "wrong answer! please try again!" ;//wrong answer

cout<<endl;
system("pause");}
if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
{
cout<<endl;
cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
cin >> SECRET_GUESS;
if(SECRET_WORD == SECRET_GUESS)// likewise
cout << "Correct the secret word was " << SECRET_WORD << endl;
else// likewise
cout << "wrong answer! please try again!" << endl;
system("pause");}

}
}
system("cls");
{
string SECRET_WORD = "phone"; // this is the word that the user is challanged to guess...

string SECRET_GUESS;// the users guess


cout << "You use it everytime you want to comnunicate with me!" << endl;
char H;
cout<<endl;
cout<<"Press H for Hint(X to cancel it)"<<endl;
cin>>H;
cout<<endl;
if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
{
cout<<" text ! "<<endl;
cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
cout<<endl;
cin >> SECRET_GUESS;
cout<<endl;
if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
else
cout << "wrong answer! please try again!" ;//wrong answer

cout<<endl;
system("pause");}
if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
{
cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
cin >> SECRET_GUESS;
if(SECRET_WORD == SECRET_GUESS)// likewise
cout << "Correct the secret word was " << SECRET_WORD << endl;
else// likewise
cout << "wrong answer! please try again!" << endl;
system("pause");}
}
system("cls");
{
string SECRET_WORD = "water"; // this is the word that the user is challanged to guess...

string SECRET_GUESS;// the users guess
cout << "You can`t live without it!" << endl;
char H;
cout<<endl;
cout<<"Press H for Hint(X to cancel it)"<<endl;
cin>>H;
cout<<endl;
if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
{
cout<<" you drink it! "<<endl;
cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
cout<<endl;
cin >> SECRET_GUESS;
cout<<endl;
if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
else
cout << "wrong answer! please try again!" ;//wrong answer

cout<<endl;
system("pause");}
if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
{
cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
cin >> SECRET_GUESS;
if(SECRET_WORD == SECRET_GUESS)// likewise
cout << "Correct the secret word was " << SECRET_WORD << endl;
else// likewise
cout << "wrong answer! please try again!" << endl;
system("pause");}
}
system("cls");


cout<<"**********GAME OVER**********";
cout<<endl;
cout<<endl;

system("pause");
return EXIT_SUCCESS;
}
Last edited on
Code cleanup:
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include<iostream>
#include<string>

using namespace std;
int main() {
cout<<"***************GUESS MY WORD GAME*************** \n";

char ans;
cout<<endl;
do
{
cout<< "PRESS Y to start! ^_^\n";
cout<< "\n\n Guess my SECRET word or face my wrath!!]\nINSTRUCTION: You can PRESS H for the given hints later when the game starts\n";
cout<<" THE LOOP WILL NOT STOP UNTIL YOU PRESS Y ........XD \n ";
cout<<"ENTER or DIE! :> ";
cin >> ans;

 }
 while((ans !='Y')&&(ans !='y')); //prompt the user to PRESS Y button to start! if the user PRESS any key except the Y button... the program will appear again and again until the Y button is PRESSED

 system("cls"); {
 string SECRET_WORD = "hair"; // this is the word that the user is challanged to guess...

 string SECRET_GUESS;// the users guess 


 cout << "its in you everywhere!" << endl;
 char H;
 cout<<endl;
 cout<<"Press H for Hint(X to cancel it)"<<endl;
 cin>>H;
 cout<<endl;
 if (H == 'H' || H == 'h'){//if the user enter H button the hint will appear! 
 cout<<"You touch it everytime you scratch your head"<<endl;
 cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
 cout<<endl;
 cin >> SECRET_GUESS;
 cout<<endl; 
 if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
 cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
 else
 cout << "wrong answer! please try again!" ;//wrong answer

 cout<<endl;
 system("pause");}
 if ((H == 'x' || H == 'X')) {// if the user PRESS X it will automatically cancel the hint
  cout<<endl;
 cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
 cin >> SECRET_GUESS;
 if(SECRET_WORD == SECRET_GUESS)// likewise
 cout << "Correct the secret word was " << SECRET_WORD << endl;
 else// likewise
 cout << "wrong answer! please try again!" << endl;
 }

 system("PAUSE");
 {cout<<"invalid command! please read the instruction once more!";

 }
 } 
 system("cls");
 {
 string SECRET_WORD = "medicine";
 string SECRET_GUESS;// the users guess 


 cout << "You need it everytime you got sick !" << endl;
 char H;
 cout<<endl;
 cout<<"Press H for Hint(X to cancel it)"<<endl;
 cin>>H;
 cout<<endl;
 if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
 {
 cout<<" it makes you better! "<<endl;
 cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
 cout<<endl;
 cin >> SECRET_GUESS;
 cout<<endl; 
 if(SECRET_WORD == SECRET_GUESS)
 cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
 else
 cout << "wrong answer! please try again!" ;//wrong answer

 cout<<endl;
 system("pause");}
 if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
 {
 cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
 cin >> SECRET_GUESS;
 if(SECRET_WORD == SECRET_GUESS)// likewise
 cout << "Correct the secret word was " << SECRET_WORD << endl;
 else// likewise
 cout << "wrong answer! please try again!" << endl;
 system("pause");}
 } 
 system("cls"); 
 {
 string SECRET_WORD = "hair"; // this is the word that the user is challanged to guess...

 string SECRET_GUESS;// the users guess 
 cout << "its in you everywhere!" << endl;
 char H;
 cout<<endl;
 cout<<"Press H for Hint(X to cancel it)"<<endl;
 cin>>H;
 cout<<endl;
 if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
 {
 cout<<"You touch it everytime you scratch your head"<<endl;
 cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
 cout<<endl;
 cin >> SECRET_GUESS;
 cout<<endl; 
 if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
 cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
 else
 cout << "wrong answer! please try again!" ;//wrong answer

 cout<<endl;
 system("pause");}
 if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
 {
 cout<<endl;
 cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
 cin >> SECRET_GUESS;
 if(SECRET_WORD == SECRET_GUESS)// likewise
 cout << "Correct the secret word was " << SECRET_WORD << endl;
 else// likewise
 cout << "wrong answer! please try again!" << endl;
 system("pause");}
 if ((H =='a' ||H =='A' ||H =='b' ||H =='B'||H =='c' ||H =='C'||H =='D' ||H =='d'||H =='e' ||H =='E'||H =='f' ||H =='F'||H =='g' ||H =='G'||H =='i' ||H =='I'||H =='j' ||H =='J'||H =='k' ||H =='K'||H =='l' ||H =='L'||H =='M' ||H =='m'||H =='n' ||H =='N'||H =='o' ||H =='O'||H =='p' ||H =='P'||H =='q' ||H =='Q'||H =='r' ||H =='R'||H =='s' ||H =='S'||H =='t' ||H =='T'||H =='u' ||H =='U'||H =='V' ||H =='v'||H =='w' ||H =='W'||H =='y' ||H =='Y'||H =='z' ||H =='Z'))
 system("pause");
 {cout<<"invalid command! please read the instruction once more!";

 }
 } 
 system("cls");
 {
 string SECRET_WORD = "phone"; // this is the word that the user is challanged to guess...

 string SECRET_GUESS;// the users guess 


 cout << "You use it everytime you want to comnunicate with me!" << endl;
 char H;
 cout<<endl;
 cout<<"Press H for Hint(X to cancel it)"<<endl;
 cin>>H;
 cout<<endl;
 if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
 {
 cout<<" text ! "<<endl;
 cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
 cout<<endl;
 cin >> SECRET_GUESS;
 cout<<endl; 
 if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
 cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
 else
 cout << "wrong answer! please try again!" ;//wrong answer

 cout<<endl;
 system("pause");}
 if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
 {
 cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
 cin >> SECRET_GUESS;
 if(SECRET_WORD == SECRET_GUESS)// likewise
 cout << "Correct the secret word was " << SECRET_WORD << endl;
 else// likewise
 cout << "wrong answer! please try again!" << endl;
 system("pause");}
 } 
 system("cls"); 
 {
 string SECRET_WORD = "water"; // this is the word that the user is challanged to guess...

 string SECRET_GUESS;// the users guess 
 cout << "You can`t live without it!" << endl;
 char H;
 cout<<endl;
 cout<<"Press H for Hint(X to cancel it)"<<endl;
 cin>>H;
 cout<<endl;
 if (H == 'H' || H == 'h')//if the user enter H button the hint will appear!
 {
 cout<<" you drink it! "<<endl;
 cout<<"Enter you Magic Guess ";// prompts the user to enter his/her SECRET_GUESS
 cout<<endl;
 cin >> SECRET_GUESS;
 cout<<endl; 
 if(SECRET_WORD == SECRET_GUESS)// if the secret word is equal to secret guess it will print out Correct the secret word was hair
 cout << "Correct the secret word was " << SECRET_WORD << endl;// right answer
 else
 cout << "wrong answer! please try again!" ;//wrong answer

 cout<<endl;
 system("pause");}
 if ((H == 'x' || H == 'X'))// if the user PRESS X it will automatically cancel the hint
 {
 cout<<"Enter you Magic Guess ";// prompt the user to enter his/her secret guess
 cin >> SECRET_GUESS;
 if(SECRET_WORD == SECRET_GUESS)// likewise
 cout << "Correct the secret word was " << SECRET_WORD << endl;
 else// likewise
 cout << "wrong answer! please try again!" << endl;
 system("pause");}
 } 
 system("cls"); 


 cout<<"**********GAME OVER**********";
 cout<<endl;
 cout<<endl;

 cin.get();
 return EXIT_SUCCESS;
 }
please help me sir! i need to randomize the questions.. thats the only problem that i got =_=..
Search up RAND c++ on google.
Assign each question a number and use the rand function per question
zzzz... its really confusing because theres a hint in every question. =_=
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
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <ctime>
#include <iostream>

int main()
{
    // a question is a pair of strings; first - word ; second - hint
    // http://www.cplusplus.com/reference/utility/pair/
    using question_t = std::pair< std::string, std::string > ;

    // create the sequence of questions (words + hints)
    // http://www.mochima.com/tutorials/vectors.html
    std::vector<question_t> questions =
    {
        { "medicine", "You need it everytime you got sick !" },
        { "quark", "Elementary particle christened by MGM" },
        { "zebra", "African equid" },
        { "equinox", "Occurs in March and in september" },
        { "muffin", "Toasted and buttered yeast-leavened bread" }
    };

    // http://en.cppreference.com/w/cpp/numeric/random/srand
    std::srand( std::time(nullptr) ) ; // one-time seed of the C lcg

    // create a random permutation of questions
    // http://en.cppreference.com/w/cpp/algorithm/random_shuffle
    std::random_shuffle( std::begin(questions), std::end(questions) ) ;

    // Ask the questions one by one:
    for( const question_t& q : questions )
    {
        std::cout << "word with " << q.first.size() << " letters\n"
                   << "hint: " << q.second << "\n\n" ;

        // ...
    }
}

http://coliru.stacked-crooked.com/a/14c177f62f551de8
NOW IVE RANDOMIZE IT .. THE NEXT PROBLEM IS HOW TO MAKE IT READ 3 QUESTIONS =_= CAN ANYONE HELP!

// "guess_word.txt"
//What_is_apple? fruit edible
//What_is_balls? round basketball
//what_is_human? animal you





#include<iostream>
#include<conio.h>
#include<fstream>
#include<time.h>
using namespace std;
main()
{
srand(time(NULL));



int rand_guess;
rand_guess = rand() % 3 + 1;
char H;
int controller = 1;


ifstream infile;
infile.open("guess_word.txt");

while (!infile.eof()) {

// string output
// infile>>output;
// cout<<output<<endl;
string question;
infile>>question;
string guess;
string answer;
infile>>answer;

string hint;
infile>>hint;

if (rand_guess == controller) {
cout<<"Question is "<<question<<endl;
//cout<<"Answer is "<<answer<<endl;
cout<<"PRESS H FOR HINT(X TO CANCEL IT)"<<endl<<"---->";
cin>>H;
if (H == 'h'||H == 'H')
{cout<<"Hint is "<<hint<<endl;


}
else if (H == 'X'||H == 'x')
cout<<"Enter your MAGIC WORD: ";
{cin>>guess;
if (guess == answer)
{cout<<"correct"<<endl;
system("pause");
return 0;}
else
{cout<<"wrong";}
system("pause");
return 0;
}
if (guess == answer)
{
cout<<"correct";
system("pause");
return 0;}
else
{cout<<"wrong";
system("pause");}
return 0;
}

controller++;


}

system("pause");
return 0;
}
Hi there,

Please don't use caps to ask your question. It is considered a shouting and impolite. Also,please wrap your code in [code][/code]-tags to make the code more readable.

JLBorges was kind enough to pretty much give you a full, working implementation of the assignment you have. Yet I don't see you using any of it in your code.

@JLBorges, thanks for that mentioning Coliru, much more customizable than ideone and much less cluttered interface.

All the best,
NwN

soooooooooooooooooory about that .. my bad ^_^ well thanks for the people who helped me XD
Topic archived. No new replies allowed.