#include "stdio.h"
#include "stdlib.h"
#include "time.h"
void guess();
main()
{
printf("You have 10$./n");
guess();
}
void guess()
{
int num=0,temp=0;
int m=10;
char c;
do
{
srand(time(NULL));
num=rand();
num=num%2+1;
printf("please press B or S:");
c=getche();
c=='b'?temp=1:(c=='s'?temp=2:exit(1));
if((temp==num)&&(temp==1)) m+=8;
if((temp==num)&&(temp==2)) m+=4;
if(temp!=num) m-=5;
printf("You have %d$/n",m);
}while((temp==1)||(temp==2));
}
该博客展示了一段C语言代码,实现了一个猜数游戏。代码包含头文件引用,主函数中提示玩家初始金额并调用猜数函数。猜数函数里通过随机数生成结果,玩家输入猜测,根据结果增减金额,直到玩家退出。
948

被折叠的 条评论
为什么被折叠?



