你的分享就是我们的动力 ---﹥

猜数字游戏(C语言版)

时间:2013-05-24 15:44来源:www.chengxuyuans.com 点击:

代码简介

没啥可以说的 GCC编译可以!别的没试。。

代码片段

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>




main(){

	int count , number , guess ;

	char yes = 'Y';



	printf("\n now let us play the game ,\n Guess the number");


	srand((int)time(0)); 
	number = 1+(int)(100.0*rand()/(RAND_MAX+1.0)); 

	//如果想偷懒 这里显示答案
	//printf("%d\n", number);

	count=0;


	do{


			do{

				printf("\n Input an integer number(1-100): ");
				scanf("%d",&guess);



			}while(!(guess>1 && guess <=100));

			
			

			if (guess==number)
			{

				printf("\ngongxi ni caidui le  thank you");
				yes ='N';


				number = 1+(int)(100.0*rand()/(RAND_MAX+1.0)); 

				//如果想偷懒 这里显示答案
				//printf("%d\n", number);


				printf("\nNEXT?(Y/N):");
				scanf("%s",&yes);

			}else{
			

			
				do
				{
					if (guess<number)
					printf("\nYour answer is LOW ,try again\n");

					if (guess>number)
					printf("\nYour answer is high ,try again\n");

					count++;
					



				} while (guess==number);

				if (count==15)
				{
						printf("\n That is the %d time ! think is hard next!");
						exit(0);
				}

				if (count<=7)
				{
						printf("\n You have got it in %d times \n",count);
						printf("\n Congretulations");
				}else{

						printf("\n You got it in %d times \n",count);
						printf("\n bet you can do it better");

				}

			}


	}while(toupper(yes)=='Y');



}

转载注明地址:http://www.chengxuyuans.com/code/C++/62147.html

推荐文章