All pastes #362517 Raw Edit

Something

public cpp v1 · immutable
·published 2007-02-18 21:46 UTC
rendered paste body
#include <iostream>#include <iomanip>#include <stdlib.h>#include <time.h> //new one here, this is so we can use the random functionusing namespace std; //just do it//GLOBAL VARIABLES this is where we define all the global variables#define EASY 15#define MEDIUM 30#define HARD 50 //these are our difficulty levelsint life; //the integer to hold the player's lifeint answer; //the integer to hold the randomly created answerint guess; //the integer to hold the player's guessvoid TakeInput(); //Gets the user's guess and passes it on to CheckResultsvoid CheckResults(); //our function to check the results and decide what to dovoid Quit(); //our quit functionint main(){life = 5; //this initialises life to 5, so that when the player restarts his life will always be 5int difficulty; //to hold the difficulty levelcout << "****************** JackPot ***********************" << endl<< "Welcome to JackPot... choose your difficulty level:" << endl << endl<< "1: Easy: Maximum number is " << EASY << endl<< "2: Medium: Maximum number is " << MEDIUM << endl<< "3: Hard: Maximum number is " << HARD << endl; //asks the user to choose difficulty levelcin >> difficulty; //gets input//converts input into a usable number for our random number functionswitch(difficulty){case '1' : difficulty = EASY;break;case '2' : difficulty = MEDIUM;break;case '3' : difficulty = HARD;break;default: difficulty = EASY;break;}srand( (unsigned) time ( NULL ) ); //our random function. the unsigned bit means it can't be negative. It's answer = rand() % difficulty; //based on the clock, hence the time.h library.TakeInput(); //Go to TakeInput(); functionreturn 0;}void TakeInput(){if (life <= 0) //if life is equal to or less than 0.{cout << "You lose!" << endl;Quit(); //go to the quit function}cout << "life: " << life << endl<< "What is your guess? "; //asks for user's inputcin >> guess; //gets user inputCheckResults(); //go to CheckResults() functionreturn;}void CheckResults(){//check the results and do your stuff!if (guess == answer){cout << "Correct - You win!" << endl;Quit(); //if correct, say so and go to Quit()}if (guess < answer){cout << "Too low! Try again... " << endl;life = life - 1;TakeInput(); //if too low, say so, lose 1 life and go to TakeInput()}if(guess > answer){cout << "Too high! Try again... " << endl;life = life - 1;TakeInput(); //if too high, say so, lose 1 life and go to TakeInput()}else{cout << "Invalid input." << endl;system("PAUSE");return;} //if user puts something weird in, say so and quit}void Quit(){system("PAUSE"); //safety netreturn;}