Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- int main(void){
- srand(time(NULL));//seed the random number
- int skittles = rand() % 1024; //get a random number between 1 and 1023
- //printf("%d\n",skittles); //used for testing
- int guess = 0;
- printf("O hai! I'm thinking of a number between 0 and 1023. What is it?\n");//prompt for initial input
- while(guess != skittles){//let the user to repeatitably guess until they get the right answer
- guess = get_int();
- if(guess < 0 || guess > 1023)
- printf("Nope! Don't be difficult. Guess again.\n");//make them guess again if invalid guess
- }
- else if(guess > skittles){
- printf("Nope! There are fewer Skittles than that. Guess again.\n");//give them a hint and make them guess again if greater
- }
- else if(guess < skittles){
- printf("Nope! There are way more Skittles that that. Guess again.\n");// give them a hint and make them guess again if less
- }
- else{
- printf("That's right! Nom nom nom.\n");// notify the user if their guess is right
- }
- }
- }
- /*output example
- O hai! I'm thinking of a number between 0 and 1023. What is it?
- 0
- Nope! There are way more Skittles than that. Guess again.
- 1
- Nope! There are way more Skittles than that. Guess again.
- -1
- Nope! Don't be difficult. Guess again.
- 1023
- Nope! There are fewer Skittles than that. Guess again.
- 42
- That's right! Nom nom nom.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement