Advertisement
daniel_lawson9999

Daniel Lawson Skittles Program

Sep 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <cs50.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. int main(void){
  7.  
  8.     srand(time(NULL));//seed the random number
  9.     int skittles = rand() % 1024; //get a random number between 1 and 1023
  10.     //printf("%d\n",skittles); //used for testing
  11.     int guess = 0;
  12.     printf("O hai! I'm thinking of a number between 0 and 1023. What is it?\n");//prompt for initial input
  13.  
  14.     while(guess != skittles){//let the user to repeatitably guess until they get the right answer
  15.         guess = get_int();
  16.         if(guess < 0 || guess > 1023)
  17.             printf("Nope! Don't be difficult. Guess again.\n");//make them guess again if invalid guess
  18.         }
  19.         else if(guess > skittles){
  20.             printf("Nope! There are fewer Skittles than that. Guess again.\n");//give them a hint and make them guess again if greater
  21.         }
  22.         else if(guess < skittles){
  23.             printf("Nope! There are way more Skittles that that. Guess again.\n");// give them a hint and make them guess again if less
  24.         }
  25.         else{
  26.             printf("That's right! Nom nom nom.\n");// notify the user if their guess is right
  27.         }
  28.     }
  29.  
  30. }
  31.  
  32.  
  33. /*output example
  34. O hai! I'm thinking of a number between 0 and 1023. What is it?
  35. 0
  36. Nope! There are way more Skittles than that. Guess again.
  37. 1
  38. Nope! There are way more Skittles than that. Guess again.
  39. -1
  40. Nope! Don't be difficult. Guess again.
  41. 1023
  42. Nope! There are fewer Skittles than that. Guess again.
  43. 42
  44. That's right! Nom nom nom.
  45. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement