| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1284 人关注过本帖
标题:请看一下,这个程序为什么有问题···(主要是循环不了··)
只看楼主 加入收藏
niufuquan1
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2015-1-29
收藏
得分:0 
回复 6楼 我FEI
好的  我会试试的!谢谢!
2015-01-30 14:07
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
收藏
得分:0 
自学中,正好学到结构体这一块。楼主的的printf()语句里面用%s格式输出的地址,实际变量又是char
改写了一下程序如下:

程序代码:
#include <stdio.h>
#define LEN 7

struct SCORE
{
    char * km[LEN];
    float  gpa[LEN];
}first;
int main(void)
{
    int i = 0;
    float e = 0.0;

    first.km[0] = "math";
    first.km[1] = "chinese";
    first.km[2] = "english";
    first.km[3] = "c";
    first.km[4] = "s";
    first.km[5] = "jd";
    first.km[6] ="physical";


    printf("This is the first score in your college\n ");
    printf("please fill in carefully!\n");
    while (i < LEN)
    {
        switch (i)
        {
        case 0 : printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 1 : printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 2: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 3: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 4: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 5: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 6: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        }
        i++;
    }
    for (i = 0; i < LEN; i++)
        e += first.gpa[i];
    printf("%.1f\n", e / LEN);

    return 0;
}


人有多懒,编程就有多难。
2015-01-30 17:21
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
收藏
得分:0 
自学中,正好学到结构体这一块。楼主的的printf()语句里面用%s格式输出的地址,实际变量又是char
改写了一下程序如下:

程序代码:
#include <stdio.h>
#define LEN 7

struct SCORE
{
    char * km[LEN];
    float  gpa[LEN];
}first;
int main(void)
{
    int i = 0;
    float e = 0.0;

    first.km[0] = "math";
    first.km[1] = "chinese";
    first.km[2] = "english";
    first.km[3] = "c";
    first.km[4] = "s";
    first.km[5] = "jd";
    first.km[6] ="physical";


    printf("This is the first score in your college\n ");
    printf("please fill in carefully!\n");
    while (i < LEN)
    {
        switch (i)
        {
        case 0 : printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 1 : printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 2: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 3: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 4: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 5: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 6: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        }
        i++;
    }
    for (i = 0; i < LEN; i++)
        e += first.gpa[i];
    printf("%.1f\n", e / LEN);

    return 0;
}


人有多懒,编程就有多难。
2015-01-30 17:21
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
收藏
得分:2 
自学中,正好学到结构体这一块。楼主的的printf()语句里面用%s格式输出的地址,实际变量又是char
改写了一下程序如下:

程序代码:
#include <stdio.h>
#define LEN 7

struct SCORE
{
    char * km[LEN];
    float  gpa[LEN];
}first;
int main(void)
{
    int i = 0;
    float e = 0.0;

    first.km[0] = "math";
    first.km[1] = "chinese";
    first.km[2] = "english";
    first.km[3] = "c";
    first.km[4] = "s";
    first.km[5] = "jd";
    first.km[6] ="physical";


    printf("This is the first score in your college\n ");
    printf("please fill in carefully!\n");
    while (i < LEN)
    {
        switch (i)
        {
        case 0 : printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 1 : printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 2: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 3: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 4: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 5: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        case 6: printf("%s: ", first.km[i]);
            scanf("%f", &first.gpa[i]);
            break;
        }
        i++;
    }
    for (i = 0; i < LEN; i++)
        e += first.gpa[i];
    printf("%.1f\n", e / LEN);

    return 0;
}


人有多懒,编程就有多难。
2015-01-30 17:22
TAAAAB
Rank: 7Rank: 7Rank: 7
来 自:湖南
等 级:黑侠
威 望:1
帖 子:243
专家分:635
注 册:2011-5-29
收藏
得分:0 
汗,网页刷新问题一下回复了这么多

人有多懒,编程就有多难。
2015-01-30 17:27
快速回复:请看一下,这个程序为什么有问题···(主要是循环不了··)
数据加载中...
 
   



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

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