| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 700 人关注过本帖
标题:谁帮我解决下问题。弄不懂了。
只看楼主 加入收藏
真的快乐
Rank: 2
等 级:论坛游民
帖 子:35
专家分:32
注 册:2013-1-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:16 
谁帮我解决下问题。弄不懂了。
程序代码:
#include<stdio.h>
#include<string.h>
    struct student        /*定义学生信息*/
    {char num;
     char name[20];
     char sex;
     char major;
     int chinese;
     int math;
     int english;
    };
    struct student str[30],*p;
void main()
{
    int com(struct student *score);
    int i;
    for(i=0;i<30;i++)        /*循环录入学生信息*/
    {scanf("%d\n",str[i].num);
     scanf("%s\n",str[i].name);
     scanf("%c\n",str[i].sex);
     scanf("%s\n",str[i].major);
     scanf("%d\n",str[i].chinese);
     scanf("%d\n",str[i].math);
     scanf("%d\n",str[i].english);
    }
    p=str;
    com(p);
}
    int com(int *score)
    {
        int a,b,c,d,e,i;
        a=b=c=d=e=0;
        for(i=0;i<30;i++)
        {switch(score[i]->chinese/10)
            case 0:
                case 1:
                    case 2:
                        case 3:
                            case 4:
                                case 5:e++;break;
                                    case 6:d++;break;
                                        case 7:c++;break;
                                            case 8:b++;break;
                                                case 9:
                                                    case 10:a++;break;
                                                        default :printf("error");
            printf("不及格:%d\n,及格:%d\n,中:%d\n,良:%d\n,优:%d\n",e,d,c,b,a);
        }



f:\新建文件夹\求和.cpp(35) : error C2227: left of '->chinese' must point to class/struct/union
f:\新建文件夹\求和.cpp(42) : error C2046: illegal case
f:\新建文件夹\求和.cpp(43) : error C2046: illegal case
f:\新建文件夹\求和.cpp(44) : error C2046: illegal case
f:\新建文件夹\求和.cpp(45) : error C2046: illegal case
f:\新建文件夹\求和.cpp(46) : error C2046: illegal case
f:\新建文件夹\求和.cpp(47) : error C2047: illegal default
f:\新建文件夹\求和.cpp(50) : fatal error C1004: unexpected end of file found    



那个switch的函数有点弄不来了。
2013-01-09 15:37
daniel_
Rank: 5Rank: 5
等 级:职业侠客
帖 子:212
专家分:307
注 册:2012-11-13
收藏
得分:0 
scanf("%d\n",str[i].num);
     scanf("%s\n",str[i].name);
     scanf("%c\n",str[i].sex);
     scanf("%s\n",str[i].major);
     scanf("%d\n",str[i].chinese);
     scanf("%d\n",str[i].math);
     scanf("%d\n",str[i].english);
------
很明显的漏了&
2013-01-09 15:46
真的快乐
Rank: 2
等 级:论坛游民
帖 子:35
专家分:32
注 册:2013-1-3
收藏
得分:0 
不是这的问题。
2013-01-09 15:51
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
switch后面的大括弧啊.......

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-01-09 15:57
h1023417614
Rank: 4
等 级:禁止访问
帖 子:211
专家分:237
注 册:2012-11-30
收藏
得分:4 
scanf("%d\n",str[i].num);
     scanf("%s\n",str[i].name);
     scanf("%c\n",str[i].sex);
     scanf("%s\n",str[i].major);
     scanf("%d\n",str[i].chinese);
     scanf("%d\n",str[i].math);
     scanf("%d\n",str[i].english);
------
有一些要加上&,,,

switch后面的大括弧漏了
2013-01-09 16:02
daniel_
Rank: 5Rank: 5
等 级:职业侠客
帖 子:212
专家分:307
注 册:2012-11-13
收藏
得分:0 
明显的问题不说了


明显是参数的问题有错
2013-01-09 16:06
daniel_
Rank: 5Rank: 5
等 级:职业侠客
帖 子:212
专家分:307
注 册:2012-11-13
收藏
得分:0 
#include<stdio.h>
#include<string.h>

    struct student        /*定义学生信息*/
    {
     char num;
     char name[20];
     char sex;
     char major;
     int chinese;
     int math;
     int english;
    };
    struct student str[30];
//    struct studen *p;

    //void com(struct student *score);

void main()
{
   
  
    int i;
    for(i=0;i<3;i++)        /*循环录入学生信息*/
    {
     scanf("%d\n",&str[i].num);
     scanf("%s\n",&str[i].name);
     scanf("%c\n",&str[i].sex);
     scanf("%s\n",&str[i].major);
     scanf("%d\n",&str[i].chinese);
     scanf("%d\n",&str[i].math);
     scanf("%d\n",&str[i].english);
    }
 
       int a,b,c,d,e,j;
        a = 0;
        b = 0;
        c = 0;
        d = 0;
        e = 0;
        for(j=0;j<3;j++)
        {
            switch(str[i].chinese/ 10)
            {
            case 0:
                case 1:
                    case 2:
                        case 3:
                            case 4:
                                case 5:
                                    e++;
                                    break;
                                    case 6:
                                        d++;
                                        break;
                                        case 7:
                                            c++;
                                            break;
                                            case 8:
                                                b++;
                                                break;
                                                case 9:
                                                    case 10:
                                                        a++;
                                                        break;
                                                        default :
                                                            printf("error");
                                                            break;
            }
           
        }
         printf("不及格:%d\n,及格:%d\n,中:%d\n,良:%d\n,优:%d\n",e,d,c,b,a);
    }



----------
参数的问题 我也不会

这样行了
2013-01-09 16:21
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:5 
哎,没大牛了,那我这和小菜就客串下吧:
就像6楼说的,明显的错误比如少地址符,,参数类型不匹配,少大括号的就不说了还有个错误是传参;
   p=str;
    com(p);
楼主通过这两句话实现参数传递的,
struct student *p;p只是一个指向struct  student类型的指针。
而在这个参数用的时候

switch(score[i]->chinese/10)
确是当成了一个指针数组来用,肯定是不行的啊

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-01-09 16:21
yaobao
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:蒙面侠
威 望:4
帖 子:1854
专家分:4121
注 册:2012-10-25
收藏
得分:0 
struct student str[30],*p[];
.
.
.
for(i=0;i<30;i++)
    p[i]=&str[i];
    com(p[0]);
.
.
switch((score+i)->chinese/10)
.
或者
for(i=0;i<30;i++)
    p[i]=&str[i];
    com(p[30]);



switch(score[i]->chinese/10)
这样貌似应该能编译通过吧
当然,7楼兄弟的方法我感觉比较好

认认真真的学习,踏踏实实的走路:戒骄戒躁!!!
2013-01-09 16:25
daniel_
Rank: 5Rank: 5
等 级:职业侠客
帖 子:212
专家分:307
注 册:2012-11-13
收藏
得分:10 
#include<stdio.h>
#include<string.h>

    struct student        /*定义学生信息*/
    {
     char num;
     char name[20];
     char sex;
     char major;
     int chinese;
     int math;
     int english;
    };
    struct student str[30];

    void com(struct student *score);

void main()
{
   
  
    int i;
    for(i=0;i<3;i++)        /*循环录入学生信息*/
    {
    printf("please input the num %d\n",i+1);
    printf("please input the name \n");
    printf("please input the sex\n");
    printf("please input the major\n");
    printf("please input the chinese score\n");
    printf("please input the math score\n");
    printf("please input the english score\n");
     scanf("%d\n",&str[i].num);
     scanf("%s\n",&str[i].name);
     scanf("%c\n",&str[i].sex);
     scanf("%s\n",&str[i].major);
     scanf("%d\n",&str[i].chinese);
     scanf("%d\n",&str[i].math);
     scanf("%d\n",&str[i].english);
    }

   
    com(str);
}
void com(struct student *score)
{
       int a,b,c,d,e,j;
        a = 0;
        b = 0;
        c = 0;
        d = 0;
        e = 0;
        for(j=0;j<3;j++)
        {
            switch(score[j].chinese/ 10)
            {
            case 0:
                case 1:
                    case 2:
                        case 3:
                            case 4:
                                case 5:
                                    e++;
                                    break;
                                    case 6:
                                        d++;
                                        break;
                                        case 7:
                                            c++;
                                            break;
                                            case 8:
                                                b++;
                                                break;
                                                case 9:
                                                    case 10:
                                                        a++;
                                                        break;
                                                        default :
                                                            printf("error");
                                                            break;
            }
           
        }
         printf("不及格:%d\n,及格:%d\n,中:%d\n,良:%d\n,优:%d\n",e,d,c,b,a);
    }



-----------
传参我也不会
这样可以通过了

有个问题 你为什么要用switch 来统计成绩的分布呢
用if else 不更好么

现在有个问题,每次你要输入八次才行。
建议别使用switch了
2013-01-09 16:36
快速回复:谁帮我解决下问题。弄不懂了。
数据加载中...
 
   



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

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