| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 323 人关注过本帖
标题:纳闷!!输入正确了,程序执行却是另一个样!!
只看楼主 加入收藏
Benthy2
Rank: 1
等 级:新手上路
帖 子:25
专家分:7
注 册:2011-12-16
结帖率:66.67%
收藏
 问题点数:0 回复次数:0 
纳闷!!输入正确了,程序执行却是另一个样!!
#include<stdio.h>
#include<string.h>
#define N 3

union sel
{
   int body;
   float jump;
};

struct student
{
   char num[10];
   char sex;
   float run;
   union sel pick;
};

void myinput(struct student *p);
void myoutput(struct student *p);

main()
{
    struct student a[N]={0};

    myinput(a);
    myoutput(a);

}


void myinput(struct student *p)
{
    int i=0;  float x=0,y=0;
   
    for(i=0;i<N;i++)
    {   
        printf("Input number,sex,100-meter dash score:");
        scanf("%s%c%f",p[i].num,&p[i].sex,&x);
        p[i].run=x;
        if(p[i].sex=='M')
        {
           printf("Entre pull-up score:");
           scanf("%d",&p[i].pick.body);
        }
        else if(p[i].sex=='F')
        {
            printf("Input long jump score:");
            scanf("%f",&y);
            p[i].pick.jump=y;
        }
        else
        {  printf("Invalid sex,input again:\n"); i--;  }
    }
}


void myoutput(struct student *p)
{
    int i=0;

    printf("Sports record:\n");
    printf(" number       sex      100-metre   pull-up    jump\n");
    for(i=0;i<N;i++)
    {
        printf("%5s%13c%13.2f",p[i].num,p[i].sex,p[i].run);
        if(p[i].sex=='M') printf("%10d\n",p[i].pick.body);
        else if(p[i].sex=='F')  printf("%20f\n",p[i].pick.jump);
    }
}


搜索更多相关主题的帖子: include number 
2011-12-19 08:59
快速回复:纳闷!!输入正确了,程序执行却是另一个样!!
数据加载中...
 
   



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

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