📄 word_jumble.cpp
字号:
// Word Jumble
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{ int score;
enum fields {WORD,HINT,NUM_FIELDS};
const int NUM_WORDS=5;
const string WORDS[NUM_WORDS][NUM_FIELDS]=
{
{"wall","Do you feel you're banging your head against something?"},
{"glasses","These might help you see the answer."},
{"labored","Going slowly,is it?"},
{"persistent","Keep at it."},
{"jumble","It's what the game is all about"}
};
srand(time(0));
int choice=(rand()%NUM_WORDS);
string theWord =WORDS[choice][WORD];
string theHint=WORDS[choice][HINT];
string jumble=theWord;
int length =jumble.size();
score=length;
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\tWelcome to Word Jumble!\n\n";
cout<<"Unscramble the letters to make a word.\n";
cout<<"Enter 'hint' for a hint.\n";
cout<<"Enter 'quit' to quit the game.\n\n";
cout<<"The jumble is:"<<jumble;
string guess;
cout<<"\n\nYour guess:";
cin>>guess;
while((guess!=theWord)&&(guess !="quit"))
{
if (guess=="hint")
{cout<<theHint;
score--;
}
else
{
cout<<"Sorry,that's not it.";
score--;
}
cout<<"\n\nYour guess: ";
cin>>guess;
}
if (guess==theWord)
cout<<"\nThat's it! You guessed it!Your score is\n"<<score;
cout<<"\nThanks for playing.\n";
cout<<"Press the enter key to exit ";
cin.ignore(cin.rdbuf()->in_avail()+1);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -