c语言课程设计篮球,帮忙完成一下这个C语言课设题目

#include

#include

#include

/**************显示菜单****************/

int MenuChoice()

{

int m;

printf("1 - 请您输入真实篮球价格(1~200元之间)\n2 - 计算机开始猜测\n3 - 退出\n");

scanf("%d", &m);

return (m);

}

/**********用户输入篮球真实价格********/

int GetPrice()

{

int price;

printf("篮球真实价格是: (元)");

scanf("%d", &price);

return (price);

}

/**********计算机猜测价格*************/

void GuessPrice(int zh)

{

int mid, low = 1, high = 200;

char s[30] = {""};

while((mid=(low+high)/2)!=zh)

{

printf("The price is: %d元\n", mid); /*************显示计算机猜测的价格*************/

if (strcmp(gets(s), "high") == 0) /**如果计算机猜测的价格偏高,用户就输入"high"**/

high=mid;

else if (strcmp(s, "low") == 0) /***如果计算机猜测的价格偏低,用户就输入"low"***/

low =mid;

}

if ((low + high) / 2 ==zh) /**计算机猜得对,则显示“正确!”,并退出程序**/

{

printf("%d元",(low + high)/2);

printf("\n正确! \n" );

}

}

/**********主函数************/

void main()

{

int choice; int x=0;

choice=MenuChoice();

if( choice==1) x=GetPrice(); /**********用户输入篮球真实价格********/

choice=MenuChoice();

if(choice==2) GuessPrice(x); /***********计算机猜测价格*************/

choice=MenuChoice();

if(choice==3) exit(0); /*****************退出*****************/

}

全部

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值