Demonburger

Trying some shit and learning

Apr 10th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.17 KB | None | 0 0
  1. //chapter 1
  2. //Make it Fancy
  3.  
  4. //Included Library Files
  5. //needed for cin, cout, endl
  6. #include <iostream>
  7. //needed for system("pause");
  8. #include <stdlib.h>
  9. //for numeric_limits
  10. #include <limits>
  11. //needed for the random number generator
  12. #include <time.h>
  13. //needed for getchar
  14. #include <stdio.h>
  15.  
  16. //using Declarations
  17. using std::cout;
  18. using std::endl;
  19. using std::cin;
  20. using std::numeric_limits;
  21. using std::streamsize;
  22.  
  23. /*this is like declaring a variable, except we're declaring a void function called GameOver*/
  24. void GameOver();
  25. void ExpensiveCalculator();
  26. void GameStats();
  27. void NumberGame();
  28. int intcheck(int x);
  29. char yncheck(char main);
  30.  
  31.  
  32.  
  33. //Starting the Main Program
  34. int main()
  35. {
  36.     char menu = 'y';
  37.     int choice;
  38.  
  39.     do
  40.     {
  41.         system("Color 0F");
  42.         cout << "Your Options are: ";
  43.         cout << "\n1 - Expensive Calculator ";
  44.         cout << "\n2 - Game Stats";
  45.         cout << "\n3 - Number Guessing Game";
  46.         cout << "\n4 - Game Over";
  47.         cout << "\nPlease Select an option: ";
  48.         cin >> choice;
  49.         choice = intcheck(choice);
  50.  
  51.         if (choice == 1)
  52.         {
  53.         /*This calls the void function ExpensiveCalculator(), the program jumps to void ExpensiveCalculator() and executes the entire function.*/
  54.         ExpensiveCalculator();
  55.         cout << endl << endl;
  56.         system("pause");
  57.         } //return a value to show successful run of main program
  58.  
  59.         else if (choice == 2)
  60.         {
  61.         /*This calls the void function GameStats, the program jumps to void GameStats() and executes the entire function.*/
  62.         GameStats();
  63.         system("pause");
  64.         cout << endl << endl;
  65.         }
  66.         else if (choice == 3)
  67.         {
  68.         NumberGame();
  69.         system("pause");
  70.         cout << endl << endl;
  71.         }
  72.         else if (choice == 4)
  73.         {
  74.         /*This calls the void function GameOver, the program jumps to void GameOver() and executes the entire function.*/
  75.         GameOver();
  76.         cout << endl << endl;
  77.         system("pause");
  78.         }
  79.         else
  80.         {
  81.            cout << "Invalid Input\n\n";
  82.         }
  83.  
  84.         cout << "Return to main Menu (y/n):";
  85.         cin >> menu;
  86.         menu = yncheck(menu);
  87.  
  88.         system("CLS");
  89.     } while (menu =='y');
  90.     //return a value to show successful run of main program
  91.     return 0;
  92. }
  93.  
  94. /*This is the void function itself, this is what runs when GameOver() is called */
  95. void GameOver()
  96. {
  97.     system("Color 1B");
  98.     system("CLS");
  99.     cout << "\t\t\tOk, Bye!\n";
  100.     cout << "#############################################################" << endl;
  101.     cout << "#                    _                                      #" << endl;
  102.     cout << "#                  -=\\`\\                                    #" << endl;
  103.     cout << "#              |\\ ____\\_\\__                                 #" << endl;
  104.     cout << "#            -=\\c`\"\"\"\"\"\"\" \"`)                               #" << endl;
  105.     cout << "#               `~~~~~/ /~~`\                                #" << endl;
  106.     cout << "#                 -==/ /                                    #" << endl;
  107.     cout << "#                   '-'                                     #" << endl;
  108.     cout << "#                  _  _                                     #" << endl;
  109.     cout << "#                 ( `   )_                                  #" << endl;
  110.     cout << "#                (    )    `)                               #" << endl;
  111.     cout << "#              (_   (_ .  _) _)                             #" << endl;
  112.     cout << "#                                             _             #" << endl;
  113.     cout << "#                                            (  )           #" << endl;
  114.     cout << "#             _ .                         ( `  ) . )        #" << endl;
  115.     cout << "#           (  _ )_                      (_, _(  ,_)_)      #" << endl;
  116.     cout << "#         (_  _(_ ,)                                        #" << endl;
  117.     cout << "#############################################################" << endl;
  118.     cout << "\t\t\tSee you later!!\n" << endl;
  119.     cout << " Please report Errors to Will. \n\n";
  120.     cout << "Game Over!" << endl;
  121. }
  122.  
  123. /*This is the void function itself, this is what runs when ExpensiveCalculator() is called */
  124. void ExpensiveCalculator()
  125. {
  126.     system("CLS");
  127.     float first, second;
  128.     int intfirst, intsecond;
  129.     cout << "Please Enter your First Number and press enter: ";
  130.     cin >> first;
  131.     cout << "Please Enter your Second Number and press enter: ";
  132.     cin >> second;
  133.     intfirst = first;
  134.     intsecond = second;
  135.     cout << first << " + " << second << " = " << first + second << endl;
  136.     cout << first << " - " << second << " = " << first - second << endl;
  137.     cout << first << " * " << second << " = " << first * second << endl;
  138.     cout << first << " / " << second << " = " << first / second << endl;
  139.     //not needed previous line does the same thing
  140.     //cout << "7.0 / 3.0 = " << 7.0 / 3.0 << endl;
  141.     cout << intfirst << " % " << intsecond << " = " << intfirst % intsecond << endl;
  142.     cout << first << " + " << second << " * 5 = " << first + second * 5 << endl;
  143.     cout << first << "(" << first << " + " << second << ") * 5 = " << (first + second) * 5 << endl;
  144. }
  145.  
  146. void GameStats()
  147. {
  148.     system("CLS");
  149.     int score;
  150.     double distance;
  151.     char playAgain;
  152.     bool shieldsUp;
  153.  
  154.     short lives, aliensKilled;
  155.  
  156.     score = 0;
  157.     distance = 1200.76;
  158.     playAgain = 'y';
  159.     shieldsUp = true;
  160.     lives = 3;
  161.     aliensKilled=10;
  162.  
  163.     double engineTemp = 6572.89;
  164.  
  165.     cout << "\nScore: " << score << endl;
  166.     cout <<"Distance: " << distance <<endl;
  167.     cout <<"Play Again: " << playAgain << endl;
  168.     //Skipping shields up
  169.     cout << "Lives :" << lives << endl;
  170.     cout << "Aliens Killed: " << aliensKilled << endl;
  171.     cout << "Engine Temp: " << engineTemp << endl;
  172.  
  173.     int fuel;
  174.     cout << "\nHow Much Fuel?";
  175.     cin >> fuel;
  176.     fuel = intcheck(fuel);
  177.  
  178.     cout << "Fuel: " << fuel << endl;
  179.  
  180.     typedef unsigned short int ushort;
  181.     ushort bonus = 10;
  182.     cout << "\nBonus: " << bonus <<
  183.      endl;
  184. }
  185. void NumberGame()
  186. {
  187.     //Initialize and assign values to variables, and get the number generator working.
  188.     srand(time(0));
  189.     int secretnumber;
  190.     int tries = 0;
  191.     int guess;
  192.     char again = 'y';
  193.     bool bFail;
  194.  
  195.     system("CLS");
  196.  
  197.     //Change Color Again
  198.     system("Color 1F");
  199.  
  200.     //Welcome Screen for number game
  201.     cout << "\n\nWelcome to Guess The Number \n";
  202.     cout << "Possible answer range is from 1 to 100.\n\n\n";
  203.  
  204.     //Main game loop, will loop while (again == y) allowing for multiple plays
  205.     while (again == 'y')
  206.     {
  207.         //Set secretnumber to a random number between 1 and 100
  208.         secretnumber = rand() % 100 + 1;
  209.  
  210.         //Loop to allow for multiple guesses
  211.         do
  212.         {
  213.             //Get input, verify input is an integer.
  214.             do
  215.             {
  216.                 cout << "Enter your guess: ";
  217.                 cin >> guess;
  218.                 //checking cin to make sure it is infact and interger,loops till interger is input
  219.                 guess = intcheck(guess);
  220.  
  221.                 //Checking to make sure input is between 1 and 100
  222.                 while (guess > 100 || guess <= 0)
  223.                 {
  224.                     cout << "Guess must be a number from 1 to 100. Please enter your guess: ";
  225.                     cin >> guess;
  226.                     //checking cin to make sure it is infact and interger,loops till interger is input, clear out extra inputs
  227.                     bFail = cin.fail();
  228.                     cin.clear();
  229.                     cin.ignore(numeric_limits<streamsize>::max(), '\n');
  230.                 }
  231.  
  232.             } while (bFail == true);
  233.  
  234.             //increment try countersystem("CLS");
  235.             ++tries;
  236.  
  237.             //Too high notification
  238.             if (guess > secretnumber)
  239.             {
  240.                 cout << "Too High! \n\n";
  241.             }
  242.  
  243.             //Too low notification
  244.             else if (guess < secretnumber)
  245.             {
  246.                 cout << "Too Low! \n\n";
  247.             }
  248.  
  249.             //Correct answer notification as well as output for number of tries
  250.             else
  251.             {
  252.                 cout << "\nThat's It! You got it in " << tries << " guesses!\n";
  253.             }
  254.  
  255.         } while (guess != secretnumber);
  256.  
  257.         //Ask user if they would like to play again this needs improved in the same way guess input needs improved
  258.         cout << "Play Number Game again (y/n)?: ";
  259.         cin >> again;
  260.         again = yncheck(again);
  261.         //Reset Try counter for next game
  262.         tries = 0;
  263.     }
  264.     cout << "Thanks for Playing My Number Game.\n\n";
  265. }
  266.  
  267. int intcheck(int xc)
  268. {
  269.     bool inputcheck;
  270.     inputcheck = cin.fail();
  271.     do
  272.     {
  273.         cin.clear();
  274.         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  275.         cout << "Please enter a valid number: ";
  276.         cin >> xc;
  277.         inputcheck = cin.fail();
  278.         cin.clear();
  279.         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  280.     }while (inputcheck == true);
  281.     return xc;
  282. }
  283.  
  284. char yncheck(char mainc)
  285. {
  286.     bool inputcheck;
  287.     inputcheck = cin.fail();
  288.     do
  289.     {
  290.         cin.clear();
  291.         cin.ignore(numeric_limits<streamsize>::max(), '\n');
  292.  
  293.         while (mainc != 'y' && mainc != 'n')
  294.         {
  295.             cout << "Please enter y or n:";
  296.             cin >> mainc;
  297.             //checking cin to make sure it is infact and interger,loops till interger is input, clear out extra inputs
  298.             inputcheck = cin.fail();
  299.             cin.clear();
  300.             cin.ignore(numeric_limits<streamsize>::max(), '\n');
  301.         }
  302.     }while (inputcheck == true);
  303.     return mainc;
  304.  
  305. }
Add Comment
Please, Sign In to add comment