Thought: The computer generates a random value and guesses if the number is correct.
#include <stdio.h> #include <stdlib.h> #include <time.h>int main () {int start = 1;while (start) {printf ( "Please select: \ n");p rintf ("****1. Play Game ******\n");p rintf ("****0. Exit game ****\n"); scanf_s ("%d", &start); switch (start) {printf ("The game Begins ****\n"), case 1:{int ret = 0;srand ((unsigned) time (NULL)), ret = rand ()% 100;//produces a number from 0 to 100 while (1) {int input = 0; printf ("You guessed: \ n"); scanf_s ("%d", &input), if (Input > Ret) {printf ("Guess big \ n");} else if (Input < ret) {printf ("Guess small \ n");} else{printf ("Congratulations, guess right!\n"); printf ("%d\n", ret);} Break;case 0:break;}} System ("pause"); return 0;}
This article is from the "Years Quiet good" blog, please make sure to keep this source http://01160529.blog.51cto.com/11479142/1794900
Guess number Game