| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 825 人关注过本帖
标题:求助~~~看下那里错了
只看楼主 加入收藏
lusan168
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-11-17
收藏
 问题点数:0 回复次数:7 
求助~~~看下那里错了
#include<stdio.h>
#include<string.h>
struct student
{
int num;
char name[20];
struct  
{
     float cj1;
  float cj2;
  float cj3;
}sanmen;
}stu[10];
void main()
{ int i=0;
  char op='y';
  for (int j=0;j<10;j++){
do{
  printf("请输入学员信息:\n");
  printf("\n学号:");
  fflush(stdin);
  scanf("%s",&stu[i].num);
  printf("姓名:");
  fflush(stdin);
  gets(stu[i].name);
  printf("三门课程的成绩:\n");
  printf("成绩1:");
  scanf("%f",&stu[i].sanmen.cj1);
  printf("成绩2:");
  scanf("%f",&stu[i].sanmen.cj2);
  printf("成绩3:");
  
    scanf("%f",&stu.sanmen.cj3);
printf("是否继续?<y or n>");
op=getchar();
i++;
}while(op=='Y' || op=='y');
  }
}
搜索更多相关主题的帖子: 信息 三门 include 课程 
2007-11-24 22:55
zhb_ice
Rank: 1
等 级:新手上路
帖 子:57
专家分:0
注 册:2007-10-6
收藏
得分:0 
定义的stu为数组
使用的时候没有加 [ ] 只用的数组名

2007-11-24 23:01
lusan168
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-11-17
收藏
得分:0 
还是错啊
#include<stdio.h>
#include<string.h>
struct student
{
    int num;
    char name[20];
    struct  
    {
     float cj1;
     float cj2;
     float cj3;
    }sanmen;
}stu[10];
void main()
{ int i=0;
  char op='y';
  for (int j=0;j<10;j++){
do{
  printf("请输入学员信息:\n");
  printf("\n学号:");
  fflush(stdin);
  scanf("%s",&stu[i].num);
  printf("姓名:");
  fflush(stdin);
  gets(stu[i].name);
  printf("三门课程的成绩:\n");
  printf("成绩1:");
   fflush(stdin);
  scanf("%f",&stu[i].sanmen.cj1);
  printf("成绩2:");
    fflush(stdin);
  scanf("%f",&stu[i].sanmen.cj2);
  printf("成绩3:");
     fflush(stdin);
    scanf("%f",&stu[i].sanmen.cj3);
    printf("是否继续?<y or n>");
    op=getchar();
    i++;
}while(op=='Y' || op=='y');
  }
}
2007-11-24 23:03
lusan168
Rank: 1
来 自:重庆
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-11-17
收藏
得分:0 
原帖由 lusan168 于 2007-11-24 23:03 发表 [url=http://bbs.][/url]
#include
#include
struct student
{
        int num;
        char name[20];
        struct  
        {
     float cj1;
         float cj2;
         float cj3;
        }sanmen;
}stu[10];
void main()
{ int i=0;
  char op='y';
  for (int j=0;j ...


其实我加了[].不知道为什么看不见.
2007-11-24 23:04
中学者
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:20
帖 子:3554
专家分:80
注 册:2007-9-14
收藏
得分:0 
程序代码:
 
#include<stdio.h>
#include<string.h>
struct student
{
int num;
char name[20];

 struct  
{
    int cj1;
  int cj2;
  int cj3;
} sanmen;
}stu[10];
void main()
{ int i=0;
  char op='y';
do{
  printf("请输入学员信息:\n");
  printf("\n学号:");
  fflush(stdin);
  scanf("%d",&stu[i].num);
  printf("姓名:");
  fflush(stdin);
  gets(stu[i].name);
  printf("三门课程的成绩:\n");
  printf("成绩1:");
  scanf("%d",&stu[i].sanmen.cj1);
  printf("成绩2:");
  scanf("%d",&stu[i].sanmen.cj2);
  printf("成绩3:");
  
    scanf("%d",&stu[i].sanmen.cj3);
printf("是否继续?<y or n>");
i++;
}while(op=='Y' || op=='y');
}

樱花大战,  有爱.
2007-11-24 23:36
pinglideyu
Rank: 3Rank: 3
来 自:武汉工程大学
等 级:论坛游侠
威 望:1
帖 子:735
专家分:140
注 册:2007-1-7
收藏
得分:0 
我说明一下,stu并不是结构体的一个对象。
所以你在引用结构体的数据成员的时候,它会提示stu并不是******must have class/struct/union type

~~我的明天我知道~~
2007-11-25 00:17
木北北
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2007-11-24
收藏
得分:0 
程序代码:
 
#include"stdio.h"
#include"string.h"
#define N 10
struct student
{

 int num;

 char name[20];

 float cj1;

 float cj2;

 float cj3;
}stu[N];
void main()
{ 
  int i,j;
  char op;
    for(j=0;j<N;j++)
  {

  printf("请输入学员信息:\n");
  printf("\n学号:");
  fflush(stdin);
  scanf("%d",&stu[j].num);
  printf("姓名:");
  fflush(stdin);
  gets(stu[j].name);
  printf("三门课程的成绩:\n");
  printf("成绩1:");
  scanf("%f",&stu[j].cj1);
  printf("成绩2:");
  scanf("%f",&stu[j].cj2);
  printf("成绩3:");
  scanf("%f",&stu[j].cj3);
  fflush(stdin);
  printf("是否继续?<y or n>");
  
  op=getchar();
  if(op=='y'||op=='Y')
  {
   continue;
  }else //跳出的同时输出.
   printf("\t学号   姓名         第一课成绩       第二课成绩      第三课成绩\n");
   break;
  }

 

 for(i=0;i<j+1;i++)  //输出stu
  printf("\t%d\t%s\t\t%3.2f\t\t%3.2f\t\t%3.2f\n",stu[i].num,stu[i].name,stu[i].cj1,stu[i].cj2,stu[i].cj3);
}

 
2007-11-25 00:20
learnerboy
Rank: 2
等 级:论坛游民
帖 子:246
专家分:22
注 册:2007-11-11
收藏
得分:0 
#include<stdio.h>
#include<string.h>
struct student
{
    int num;
    char name[20];
    union
    {
    float cj1;
    float cj2;
    float cj3;
    }sanmen;
}stu[10];
void main()
{
    int i=0,j;
    char op='y';
    for (j=0;j<10;j++)
    {
        do{
            printf("请输入学员信息:\n");
            printf("\n学号:");
            fflush(stdin);
            scanf("%s",&stu[j].num);
            printf("姓名:");
            fflush(stdin);
            gets(stu[j].name);
            printf("三门课程的成绩:\n");
            printf("成绩1:");
            scanf("%f",&stu[j].sanmen.cj1);
            printf("成绩2:");
            scanf("%f",&stu[j].sanmen.cj2);
            printf("成绩3:");
            scanf("%f",&stu[j].sanmen.cj3);
            printf("是否继续?<y or n>");
            op=getchar();
            i++;
          }while(op=='Y' || op=='y');
    }
}
2007-11-25 01:09
快速回复:求助~~~看下那里错了
数据加载中...
 
   



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

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