Jump to content

K1u's Guessing Game


K1u
 Share

Recommended Posts

Coded for competition - http://k0h.org/portal/index.php?option=com...mp;topic=1792.0

#include <cstdlib>
#include <iostream>

/*
K1u's Guessing Game.
Author: K1u.
Site: k0h.org.
Description: Defines a random number that the user must attempt to guess.
Disclaimer: I am not responsible for any damages this program my create.
I am not responsible for how you use this program.
*/

using namespace std;

int numGuesses = 3; /* Define the number of guesses. */

void game(void)
    {
    /*
    Declaration of variables.
    */
    int guessedNum; /* Guessed Number. The number you input. */
    string choice; /* Choice for playing again. */
       
    cout << "What is the random number?n" << "It is a number from 1 to 5!n";
    cin >> guessedNum;
   
    /* If the number is less or equal to 5 and greater 0
    the program will proceed. */
    if (guessedNum <= 5 && guessedNum > 0)
    {
    /* Seeding of the Random Number Generator. */
    srand(time(NULL));
    int rnum = rand() % 5 + 1;
   
         if (guessedNum == rnum)
         {
            cout << "Correct!n";
         }
         
         else if (guessedNum != rnum)
         {
              /* If the number guessed is not correct then decrease the
              number of guesses. */
              numGuesses--;
              cout << "Incorrect!n";     
              cout << "You only have " << numGuesses << " more guesses left!n";
             
              /* If the number of guesses the user has made is less or equal to 0
              then game over. */
              if (numGuesses <= 0)
              {
                   cout << "Bye!n";
              }
             
              else
              {
                   game();
              }
              }
         }
         
         /* If the number is greater than 5 and less than 0. */
         else
         {
              cout << "Number must be between 1 and 5.n";
              cout << "Wish to play again?n" << "Yes or Non";
             
              cin >> choice;
             
              if (choice == "Yes")
              {
                    game();
              }
   
              else
              {
                    cout << "Bye!n";   
              }
              }
          }
             
int main(void)
             {
             /* We call upon the function game. */
             game();
             system("pause");
             return 0;
             }

Link to comment
Share on other sites

I was at school, bored so i did it on my TI-83 PLus calculator

Ti-83 Plus Code:

goto 0
.:By Sablefoxx:.:
Lbl 0
ClrHome
DelVar X
DelVar Y
randInt(1,100)->X
Disp "I am thinking"
Disp " of a Number"
Disp "Between"
input "1 and 100: ", Y
goto 5
Lbl 5
If Y=X
goto 1
If Y>X 
goto 2
If Y<X
goto 3
Lbl 1
ClrHome
Disp "You Win it Was", X
pause
goto 0
Lbl 2
Clr Home
Disp "You Are Wrong"
Disp "It is Lower then", Y
pause
goto 4
Lbl 3
ClrHome
Disp "Wrong! Guess"
Disp "Higher then", Y
pause
goto 4
Lbl 4
ClrHome
DelVar Y
input "Guess Again: ", Y
goto 5

NOTE: to get the '->' on line 5 use the 'STO->' key above 'ON'

and you do not type out commands you must choose them from a menu, most can found in the CATALOG

To make it start calc press PRGM then Press the '-->' until "new" is highlighted press ENTER, press [TAN] [5] [sIN] [LN] [LN] to name it "GUESS" type in code above if you cannot find a certain command try pressing '2nd' then 0 to bring up the CATALOG with just about every Ti-83 command in it.  To Run it goto your home (press 2nd [MODE]) press [PRGM] and select "GUESS" from the menu.  Good Luck!

Enjoy and happy slacking!

Link to comment
Share on other sites

I was at school, bored so i did it on my TI-83 PLus calculator

Ti-83 Plus Code:

goto 0
.:By Sablefoxx:.:
Lbl 0
ClrHome
DelVar X
DelVar Y
randInt(1,100)->X
Disp "I am thinking"
Disp " of a Number"
Disp "Between"
input "1 and 100: ", Y
goto 5
Lbl 5
If Y=X
goto 1
If Y>X 
goto 2
If Y<X
goto 3
Lbl 1
ClrHome
Disp "You Win it Was", X
pause
goto 0
Lbl 2
Clr Home
Disp "You Are Wrong"
Disp "It is Lower then", Y
pause
goto 4
Lbl 3
ClrHome
Disp "Wrong! Guess"
Disp "Higher then", Y
pause
goto 4
Lbl 4
ClrHome
DelVar Y
input "Guess Again: ", Y
goto 5

NOTE: to get the '->' on line 5 use the 'STO->' key above 'ON'

and you do not type out commands you must choose them from a menu, most can found in the CATALOG

To make it start calc press PRGM then Press the '-->' until "new" is highlighted press ENTER, press [TAN] [5] [sIN] [LN] [LN] to name it "GUESS" type in code above if you cannot find a certain command try pressing '2nd' then 0 to bring up the CATALOG with just about every Ti-83 command in it.  To Run it goto your home (press 2nd [MODE]) press [PRGM] and select "GUESS" from the menu.  Good Luck!

Enjoy and happy slacking!

cool

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...