Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //chapter 1
- //Make it Fancy
- //Included Library Files
- //needed for cin, cout, endl
- #include <iostream>
- //needed for system("pause");
- #include <stdlib.h>
- //for numeric_limits
- #include <limits>
- //needed for the random number generator
- #include <time.h>
- //needed for getchar
- #include <stdio.h>
- //using Declarations
- using std::cout;
- using std::endl;
- using std::cin;
- using std::numeric_limits;
- using std::streamsize;
- /*this is like declaring a variable, except we're declaring a void function called GameOver*/
- void GameOver();
- void ExpensiveCalculator();
- void GameStats();
- void NumberGame();
- char yncheck(char main);
- //Starting the Main Program
- int main()
- {
- char menu = 'y';
- int choice;
- bool inputfail;
- do
- {
- system("Color 0F");
- cout << "Your Options are: ";
- cout << "\n1 - Expensive Calculator ";
- cout << "\n2 - Game Stats";
- cout << "\n3 - Number Guessing Game";
- cout << "\n4 - Game Over";
- cout << "\nPlease select an option and press enter: ";
- cin >> choice;
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- //Checking to make sure input is a menu option
- while (choice > 4 || choice <= 0)
- {
- cout << "Please Try Again .\nYour Options are: ";
- cout << "\n1 - Expensive Calculator ";
- cout << "\n2 - Game Stats";
- cout << "\n3 - Number Guessing Game";
- cout << "\n4 - Game Over";
- cout << "\nPlease select an option and press enter: ";
- cin >> choice;
- //checking cin to make sure it is in fact and integer,loops till integer is input, clear out extra inputs
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- if (choice == 1)
- {
- /*This calls the void function ExpensiveCalculator(), the program jumps to void ExpensiveCalculator() and executes the entire function.*/
- ExpensiveCalculator();
- cout << endl << endl;
- system("pause");
- } //return a value to show successful run of main program
- else if (choice == 2)
- {
- /*This calls the void function GameStats, the program jumps to void GameStats() and executes the entire function.*/
- GameStats();
- system("pause");
- cout << endl << endl;
- }
- else if (choice == 3)
- {
- NumberGame();
- system("pause");
- cout << endl << endl;
- }
- else if (choice == 4)
- {
- /*This calls the void function GameOver, the program jumps to void GameOver() and executes the entire function.*/
- GameOver();
- cout << endl << endl;
- system("pause");
- }
- else
- {
- cout << "Invalid Input\n\n";
- }
- cout << "Return to main Menu (y/n):";
- menu = getchar();
- menu = yncheck(menu);
- system("CLS");
- } while (menu =='y');
- //return a value to show successful run of main program
- return 0;
- }
- /*This is the void function itself, this is what runs when GameOver() is called */
- void GameOver()
- {
- system("Color 1B");
- system("CLS");
- cout << "\t\t\tOk, Bye!\n";
- cout << "#############################################################" << endl;
- cout << "# _ #" << endl;
- cout << "# -=\\`\\ #" << endl;
- cout << "# |\\ ____\\_\\__ #" << endl;
- cout << "# -=\\c`\"\"\"\"\"\"\" \"`) #" << endl;
- cout << "# `~~~~~/ /~~`\ #" << endl;
- cout << "# -==/ / #" << endl;
- cout << "# '-' #" << endl;
- cout << "# _ _ #" << endl;
- cout << "# ( ` )_ #" << endl;
- cout << "# ( ) `) #" << endl;
- cout << "# (_ (_ . _) _) #" << endl;
- cout << "# _ #" << endl;
- cout << "# ( ) #" << endl;
- cout << "# _ . ( ` ) . ) #" << endl;
- cout << "# ( _ )_ (_, _( ,_)_) #" << endl;
- cout << "# (_ _(_ ,) #" << endl;
- cout << "#############################################################" << endl;
- cout << "\t\t\tSee you later!!\n" << endl;
- cout << "Please report Errors to Will. \n\n";
- cout << "Game Over!" << endl;
- }
- /*This is the void function itself, this is what runs when ExpensiveCalculator() is called */
- void ExpensiveCalculator()
- {
- system("CLS");
- int first, second;
- bool inputfail;
- cout << "Please Enter your First Number and press enter: ";
- cin >> first;
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- //Checking to make sure input is a menu option
- while (inputfail == true)
- {
- cout << "Please re-enter your First Number and press enter: ";
- cin >> first;
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- cout << "Please Enter your Second Number and press enter: ";
- cin >> second;
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- //Checking to make sure input is a menu option
- while (inputfail == true)
- {
- cout << "Please re-enter your second Number and press enter: ";
- cin >> second;
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- cout << first << " + " << second << " = " << first + second << endl;
- cout << first << " - " << second << " = " << first - second << endl;
- cout << first << " * " << second << " = " << first * second << endl;
- cout << first << " / " << second << " = " << first / second << endl;
- //not needed previous line does the same thing
- //cout << "7.0 / 3.0 = " << 7.0 / 3.0 << endl;
- cout << first << " % " << second << " = " << first % second << endl;
- cout << first << " + " << second << " * 5 = " << first + second * 5 << endl;
- cout << first << "(" << first << " + " << second << ") * 5 = " << (first + second) * 5 << endl;
- }
- void GameStats()
- {
- system("CLS");
- int score;
- double distance;
- char playAgain;
- bool shieldsUp, inputfail;
- short lives, aliensKilled;
- score = 0;
- distance = 1200.76;
- playAgain = 'y';
- shieldsUp = true;
- lives = 3;
- aliensKilled=10;
- double engineTemp = 6572.89;
- cout << "\nScore: " << score << endl;
- cout <<"Distance: " << distance <<endl;
- cout <<"Play Again: " << playAgain << endl;
- //Skipping shields up
- cout << "Lives :" << lives << endl;
- cout << "Aliens Killed: " << aliensKilled << endl;
- cout << "Engine Temp: " << engineTemp << endl;
- int fuel;
- cout << "\nHow Much Fuel?";
- cin >> fuel;
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- //Checking to make sure input is a menu option
- while (inputfail == true)
- {
- cout << "Please re-enter your fuel and press enter: ";
- cin >> fuel;
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- cout << "Fuel: " << fuel << endl;
- typedef unsigned short int ushort;
- ushort bonus = 10;
- cout << "\nBonus: " << bonus <<
- endl;
- }
- void NumberGame()
- {
- //Initialize and assign values to variables, and get the number generator working.
- srand(time(0));
- int secretnumber;
- int tries = 0;
- int guess;
- char again = 'y';
- bool inputfail;
- system("CLS");
- //Change Color Again
- system("Color 1F");
- //Welcome Screen for number game
- cout << "\n\nWelcome to Guess The Number \n";
- cout << "Possible answer range is from 1 to 100.\n\n\n";
- //Main game loop, will loop while (again == y) allowing for multiple plays
- while (again == 'y')
- {
- //Set secretnumber to a random number between 1 and 100
- secretnumber = rand() % 100 + 1;
- //Loop to allow for multiple guesses
- do
- {
- //Get input, verify input is an integer.
- do
- {
- cout << "Enter your guess: ";
- cin >> guess;
- //checking cin to make sure it is in fact and integer,loops till integer is input
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- //Checking to make sure input is between 1 and 100
- while (guess > 100 || guess <= 0)
- {
- cout << "Guess must be a number from 1 to 100. Please enter your guess: ";
- cin >> guess;
- //checking cin to make sure it is in fact and integer,loops till integer is input, clear out extra inputs
- inputfail = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- } while (inputfail == true);
- //increment try counter
- ++tries;
- //Too high notification
- if (guess > secretnumber)
- {
- cout << "Too High! \n\n";
- }
- //Too low notification
- else if (guess < secretnumber)
- {
- cout << "Too Low! \n\n";
- }
- //Correct answer notification as well as output for number of tries
- else
- {
- cout << "\nThat's It! You got it in " << tries << " guesses!\n";
- }
- } while (guess != secretnumber);
- //Ask user if they would like to play again this needs improved in the same way guess input needs improved
- cout << "Play Number Game again (y/n)?: ";
- again = getchar();
- again = yncheck(again);
- //Reset Try counter for next game
- tries = 0;
- }
- cout << "Thanks for Playing My Number Game.\n\n";
- }
- char yncheck(char mainc)
- {
- bool inputcheck;
- inputcheck = cin.fail();
- do
- {
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- while (mainc != 'y' && mainc != 'n')
- {
- cout << "Please enter y or n:";
- cin >> mainc;
- //checking cin to make sure it is infact and interger,loops till interger is input, clear out extra inputs
- inputcheck = cin.fail();
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- }while (inputcheck == true);
- return mainc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement