Let's play a little game together!
Srand ((unsigned int) time (NULL));//set random number of times
Ret=rand ()%100; Generate 0~100 Random number
Add #include <time.h>
Change the value of 100 so that it produces 0~ other random numbers.
Custom Game Menus menu.
#include <stdio.h> #include <stdlib.h> #include <time.h>void fun1 (int ret,int count)//game Subject {int i=0;int num=0;printf ("please input 0~100 \n");d o{if (i>= Count) {printf (" You're too lame! \ n ");//printf (" you are too weak\n "); break;} printf ("please input number:>"); scanf ("%d", &num); if (num == 99999) {break;} I++;if (Num>ret) {printf ("too big\n");} Else if (Num<ret) {printf ("too small\n");} else { printf ("success\n"); }}while ( Num-ret);} VOID&NBSP;FUN2 (ret)//game level {int c=0;int s=0;printf ("1 is extremely difficult, 2 is difficult, 3 is medium, 4 is general, 5 is simple \ n");p rintf ("please Input 1~5 rank:\n "); scanf ("%d ", &c); if (c==1) {s=2;} if (c==2) {s=5;} if (c==3) {s=10;} if (c==4) {s=15;} if (c==5) {s=20;} FUN1 (ret,s);} VOID&NBSP;FUN3 (ret) //game custom number {int c=0;printf ("Please input guess the number of times:\n "); scanf ("%d ", &c); fun1 (ret,c);} Void menu () {printf ("\t\t\t*****************************\n");p rintf ("\t\t\t******** 1. Start Game *********\n ");p rintf (" \t\t\t******** 2. Game level *********\n ");p rintf (" \t\t\t******** 3. Custom guess Count ***\n ");p rintf (" \t\t\t******** 0. Exit game *********\n ");p rintf (" \t\t\t********************* \ n ");} Int main () {int ret=0;int choice=0;int c=50;//Sets the initial number of game guesses Srand ((unsigned int) Time (NULL )///Set random number of changes over time menu ();p rintf ("welcome to guess number game!\n");p rintf ("***input 99999,game comeover***\n ");p rintf (" Please input choice: "); scanf ("%d ", &choice); Ret=rand ()% 100; //generate 0~100 Random number switch (choice) { case 1: fun1 (ret,c); &NBSP;BREAK;&NBSP;&NBSP;&NBSP;&NBSP;CASE&NBSP;2:&NBSP;&NBSP;FUN2 (ret); break; &NBSP;CASE&NBSP;3:&NBSP;&NBSP;FUN3 (ret); break; default: break;& NBsP;} return 0;}
You are welcome to participate in the game and point out deficiencies.
This article is from the "Na-dimensional Snow" blog, please be sure to keep this source http://1536262434.blog.51cto.com/10731069/1702965
"C" games--word-guessing games