| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 611 人关注过本帖
标题:求助 关于if else以及循环问题
取消只看楼主 加入收藏
xunxicyuyan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-7-1
结帖率:0
收藏
已结贴  问题点数:10 回复次数:5 
求助 关于if else以及循环问题
录入一定数据并进行查找,如不匹配则else单纯循环,无论输入值是否正确都只输出else语句内容
代码如下:

#include<stdio.h>
    struct personnel{
    char name[15],birthplace[15];
    int age, id;
    //if the input ID is not int, the next two line will appear together//
    //what is the problem?//
    //Answer: the later Enter in the buffer makes the gets() skip//
    //add flushall() will do good//
};
int ctr,check;
main()
{
    struct personnel profile[3];
    for(ctr=0; ctr<2; ctr++)
    {
      printf("\n%d.Hello, what's your name?\n", ctr+1);
      gets(profile[ctr].name);
      puts("\nwhat's your id number?");
      scanf(" %d", &profile[ctr].id);
      fflush(stdin);
      puts("\nOk, what's your birthplace?");
      gets(profile[ctr].birthplace);
      fflush(stdin);
      puts("\nAlright, what's your age");
      scanf(" %d", &profile[ctr].age);
      fflush(stdin);
    }
      puts("Which ID do you want to check:");
      scanf(" %d", &check);
    for(ctr=0; ctr<2; ctr++)
    {if(check == profile[ctr].id)
      {
      printf("\nThe id you are checking is %d, name:%s, age:%d, born:%s\n\n",
      profile[ctr].id, profile[ctr].name, profile[ctr].age,
      profile[ctr].birthplace);
      break;
      }
     else
      {
          puts("Please type in correct id number");
          fflush(stdin);
       scanf(" %d", &check);
       continue;
      }
    }
   }
搜索更多相关主题的帖子: together include problem profile appear 
2015-07-01 10:33
xunxicyuyan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-7-1
收藏
得分:0 
没人回答楼主吗
2015-07-01 11:47
xunxicyuyan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-7-1
收藏
得分:0 
回复 3楼 林月儿
会是我使用的编译器的问题吗?我用的C-Free5.0
2015-07-01 11:58
xunxicyuyan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-7-1
收藏
得分:0 
回复 7楼 luoye1994
好像不是吧 清空前不已经存到相应地址了?
2015-07-01 15:03
xunxicyuyan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-7-1
收藏
得分:0 
回复 5楼 自傲
小白 我试试
2015-07-01 15:04
xunxicyuyan
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-7-1
收藏
得分:0 
回复 6楼 TAAAAB
为了方便 我就测试2组数据啊
2015-07-01 15:04
快速回复:求助 关于if else以及循环问题
数据加载中...
 
   



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

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