| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 393 人关注过本帖
标题:用结构体建立成绩档案再重复输出,循环部分有问题
只看楼主 加入收藏
q987456963q
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-11-1
结帖率:0
收藏
 问题点数:0 回复次数:6 
用结构体建立成绩档案再重复输出,循环部分有问题
代码如下
#include
#include
#include
struct student
{
    char Num[10];
    char Name[15];
    int type;
    int total;
};
int main()
{
    struct student stud1[100];
    int i,j,n;
    int x=1;
    char k[10];
    printf("input how many student you need to input:");
    scanf("%d",&n);
    printf("input number\tname\tstudenttype(major 1. in science 2.in arts)\ttotal:\n");
    for(i=0;i<N;I++)
    {
        scanf("%s\t",&stud1[i].Num);
        scanf("%s\t",&stud1[i].Name);
        scanf("%d\t",&stud1[i].type);
        scanf("%d\t",&stud1[i].total);
    }
    printf("\n");
    if(x==1)
    {
       printf("input the number you search:");
       scanf("%s",&k);
       printf("\n");
       for(i=0;i<N;I++)
       {
          if(strcmp(stud1[i].Num,k)==0)
          {
             printf("%s\t",stud1[i].Num);
             printf("%s\t",stud1[i].Name);
             printf("type %d\t\t",stud1[i].type);
             printf("%d",stud1[i].total);
             printf("\n");
          }
       }
       printf("input 1 to input again or 2 to out:");
       scanf("%d",&x);
       printf("\n");
    }
    return 0;
}
搜索更多相关主题的帖子: include science number 结构体 
2014-05-08 21:05
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
问题太多了,能编译过吗?

总有那身价贱的人给作业贴回复完整的代码
2014-05-08 21:10
q987456963q
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-11-1
收藏
得分:0 
中间没问题,有的话大概只是逻辑错误
2014-05-08 21:11
q987456963q
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-11-1
收藏
得分:0 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct student
{
    char Num[10];
    char Name[15];
    int type;
    int total;
};
int main()
{
    struct student stud1[100];
    int i,j,n;
    int x=1;
    char k[10];
    printf("input how many student you need to input:");
    scanf("%d",&n);
    printf("input number\tname\tstudenttype(major 1. in science 2.in arts)\ttotal:\n");
    for(i=0;i<n;i++)
    {
        scanf("%s\t",&stud1[i].Num);
        scanf("%s\t",&stud1[i].Name);
        scanf("%d\t",&stud1[i].type);
        scanf("%d\t",&stud1[i].total);
    }
    printf("\n");
    if(x==1)
    {
       printf("input the number you search:");
       scanf("%s",&k);
       printf("\n");
       for(i=0;i<n;i++)
       {
          if(strcmp(stud1[i].Num,k)==0)
          {
             printf("%s\t",stud1[i].Num);
             printf("%s\t",stud1[i].Name);
             printf("type %d\t\t",stud1[i].type);
             printf("%d",stud1[i].total);
             printf("\n");
          }
       }
       printf("input 1 to input again or 2 to out:");
       scanf("%d",&x);
       printf("\n");
    }
    return 0;
}
2014-05-08 21:12
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
回复 4 楼 q987456963q
你能先写个输入整数,再把整数打印出来吗?

总有那身价贱的人给作业贴回复完整的代码
2014-05-08 21:44
q987456963q
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-11-1
收藏
得分:0 
if(x==1)
    {
       printf("input the number you search:");
       scanf("%s",&k);
       printf("\n");
       for(i=0;i<n;i++)
       {
          if(strcmp(stud1[i].Num,k)==0)
          {
             printf("%s\t",stud1[i].Num);
             printf("%s\t",stud1[i].Name);
             printf("type %d\t\t",stud1[i].type);
             printf("%d",stud1[i].total);
             printf("\n");
          }
       }
       printf("input 1 to input again or 2 to out:");
       scanf("%d",&x);
       printf("\n");
    }
    return 0;
这一段中的两个scanf都跳过了
2014-05-08 21:46
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
真是引导不了,动动手就这么费劲

总有那身价贱的人给作业贴回复完整的代码
2014-05-09 07:09
快速回复:用结构体建立成绩档案再重复输出,循环部分有问题
数据加载中...
 
   



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

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