C++ jumble word game



#include<iostream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;
int main(){
string jumbled[5][2]={{"dangerous","you should avoid it"},
{"programming","this is what you are doing right now"},
{"jumble","this is what the game is all about"},
{"transformers","famous movie"},
{"counterstrike","popular game "}
};
int word=0,hint=0;

srand(static_cast<unsigned int>(time(0)));

int choice=(rand()%5);

string theword=jumbled[choice][word];

string thehint=jumbled[choice][1];
 
string jumble=theword;

int length=jumble.size();

for(int i=0;i<length;i++){

int parameter1=(rand()%length);

int parameter2=(rand()%length);

char temp=jumble[parameter1];

jumble[parameter1]=jumble[parameter2];

jumble[parameter2]=temp;
}
cout<<"type hint if you want hint"<<endl;

cout<<"type quit if you want to quit"<<endl;

cout<<"the jumbled word= "<<jumble<<endl;

string guess;

cout<<"enter your guess =  ";

cin >> guess;

while(guess!=theword && guess!="quit"){
if(guess=="hint"){
cout<<thehint;
}
else {
cout<<"you have got wrong answer "<<endl<<endl;
}
cout<<endl<<" guess again = ";
cin>>guess;

}

if(guess==theword){
cout<<endl<<"you guessed it right "<<endl;
}
}






Previous
Next Post »

1 comments:

Write comments
Unknown
AUTHOR
8 May 2022 at 11:53 delete

i want to add two more word and hint but i couldnt do it can you please help me

Reply
avatar

Comments:

Disqus Shortname