| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1090 人关注过本帖
标题:新手求解大神猜数字问题编法
只看楼主 加入收藏
hushuncheng
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-10-9
结帖率:25%
收藏
已结贴  问题点数:10 回复次数:2 
新手求解大神猜数字问题编法
程序内容:两个人互相猜数字,先分别输入一个ASCII符号(从33到96)后隐藏,然后挨个猜对方的答案,正确则欢呼并告知猜了多少次,错误则告诉偏大偏小并换另外一个人猜。猜完后,会提问是否继续,继续则重新开始,否则结束....
#include <time.h>
main()
{
 int a,b,c;
 printf("Player A, please write your number and press enter to keep it secret: ",a);
 scanf("%d", &a);
 system("cls");
 printf("Player B, please write your number and press enter to keep it secret:",b);
 scanf("%d",&b);
 system("cls");
 printf("Come on! Show Time!");
 while(a)
 {
 int i=0;
 printf("Player A, Please write the number you guess:");
 scanf("%d",&c);
 if(c==b)
 {
  printf ("OMG,congratulations!you get the correct answer!\n");
  printf ("You have tried %d times\n",i);
  i++;
  break; }
 
  if(c>b)
   printf("well, your number is too large and turn for player B.\n");
   i++;
  if(c<b)
   printf("well,your number is too small and turn for player B.\n");
   i++;
}
return 0
}


不知道怎么记录累积的次数并且换人...求大神讲解
搜索更多相关主题的帖子: include secret please system number 
2016-10-17 19:17
word123
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:13
帖 子:333
专家分:1622
注 册:2014-4-5
收藏
得分:10 
//就在你的程序上该了点,并且加了点程序
#include <time.h>
#include <stdlib.h>
#include<stdio.h>
int main()
{
 int a,b,c;
 int who;
 int Btime,Atime;
 int over;
 int ch;
 do{
     printf("Player A, please write your number and press enter to keep it secret: ");
     scanf("%d", &a);
     system("cls");
     printf("Player B, please write your number and press enter to keep it secret:");
     scanf("%d",&b);
     system("cls");
     printf("Come on! Show Time!");
     Atime=0;Btime=0;who=0;over=0;
 while(true)
 {
     switch(who){
     case 0:
        printf("Player A, Please write the number you guess:");
        scanf("%d",&c);
        Atime++;
         if(c==b)
         {
          printf ("OMG,congratulations!you get the correct answer!\n");
          printf ("You have tried %d times\n",Atime);
          over=1;
         }else if(c>b)
           printf("well, your number is too large and turn for player B.\n");
          else
           printf("well,your number is too small and turn for player B.\n");
        who=1;
         break;
     case 1:
        printf("Player B, Please write the number you guess:");
        scanf("%d",&c);
        Btime++;
         if(c==a)
         {
          printf ("OMG,congratulations!you get the correct answer!\n");
          printf ("You have tried %d times\n",Btime);
          over=1;
         }else if(c>a)
           printf("well, your number is too large and turn for player A.\n");
         else
           printf("well,your number is too small and turn for player A.\n");
        who=0;
         break;
     }
     if(over==1)
         break;
 }
     printf("is go on?(1/0)");
     scanf("%d",&ch);
}while(ch==1);
return 0;
}
2016-10-18 00:26
hushuncheng
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2016-10-9
收藏
得分:0 
回复 2楼 word123
哇哇哇!!!谢谢大侠~谢谢大神~
2016-10-18 15:50
快速回复:新手求解大神猜数字问题编法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042730 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved