码迷,mamicode.com
首页 > 编程语言 > 详细

c语言小程序:编写猜字游戏

时间:2015-10-28 07:12:19      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:c语言   猜字游戏   

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main()

{

int input=1;

printf("欢迎使用猜数字游戏\n");

while (input)

{

   printf("**********************\n");

   printf("******* 1.start ******\n");

   printf("******* 0. exit ******\n");

   printf("**********************\n");

printf("请选择>");

scanf("%d", &input);

                //开始玩游戏

switch (input)

{

case 1:

{

int n=0;

int ch=0;

srand((unsigned int)time(NULL));//随机值产生之前先设定一个种子(time)

n=rand()%101;//随机产生一个1-100之间的数

while(1)

{

printf("请猜一个(0-100)直接的数\n");

scanf("%d", &ch);

if(ch>n)

{

printf("你猜大了\n");

}

else if(ch<n)

{

printf("你猜小了\n");

}

else

{

printf("恭喜你,猜对了\n");

break;

}

}

break;

}

default:

printf("游戏退出\n");

break;

}

}

return 0;

}


本文出自 “阳光下的向日葵” 博客,请务必保留此出处http://10796797.blog.51cto.com/10786797/1706934

c语言小程序:编写猜字游戏

标签:c语言   猜字游戏   

原文地址:http://10796797.blog.51cto.com/10786797/1706934

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!