Public feed #724334

Unnamed

public cpp v1 · immutable
Raw Edit
·published 2007-10-03 14:42 UTC
rendered paste body
//Word Jumble - The classic word jumble game where the play can ask for a hint#include <iostream>#include <string>#include <cstdlib>#include <ctime>using namespace std;int main(){	enum fields {WORD, HINT, NUM_FIELDS};	const int NUM_WORDS = 10;	const string WORDS[NUM_WORDS][NUM_FIELDS]= {		{"wall", "Do you feel you're banging your head against something?"},		{"glasses", "Wank too much, and you may need a pair."},		{"drugs", "They enhance the lols"},		{"persistant", "Keep at it. "},		{"jumble", "Its what the game is all about."},		{"laptop", "Portable computery goodness"},		{"banana", "The phallus like fruit"},		{"gonorrhea", "The STD that makes the world go around"},		{"fear", "JC is a haxor on it"},		{"god", "Smoko is the one and only"}	};	cout << "\t\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";	int playing = 1;	int tries = 1; int score = 0;	while(playing){		//Jumble the word		srand(time(0));		int choice = (rand() % NUM_WORDS);		string theWord = WORDS[choice][WORD]; //the word to guess		string theHint = WORDS[choice][HINT]; //the hint for the word		string jumble = theWord; //jumbled version of the 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 << "The jumble is: " << jumble;		string guess;		cout << "\n\nYour guess: ";		cin >> guess;		//Loop over this unless the user wants to quit, or gets it right		while((guess != theWord) && (guess != "quit")){			if(guess == "hint"){				cout << theHint;				score--;			} else{				cout << "Sorry, that's not it.";				tries++;			}								cout << "\n\nYour guess: ";			cin >> guess;		}		//Tell the user they got it right, and how many tries it took.		if(guess == theWord){			cout << "\nYou guessed it!\n";			cout << "It took you " << tries << " to guess the word.\n\n";			score++;			tries = 1;		}		//The user wants to quit, tell them their score and wait for them to exit.		if(guess == "quit"){			cout << "\n\nYour score for this round was " << score << "!\n";			cout << "Press any key to quit...";			playing = 0;		}	}	cin.get();	cin.get();	return 0;}