| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 323 人关注过本帖
标题:请各位高手帮忙看一下,哪里错了
只看楼主 加入收藏
zhouxiangron
Rank: 2
等 级:论坛游民
帖 子:19
专家分:20
注 册:2010-7-9
结帖率:42.86%
收藏
已结贴  问题点数:20 回复次数:4 
请各位高手帮忙看一下,哪里错了
这几天学到了结构体,写了代码,但是出错,请各位给我看看:
程序代码:
#include <stdio.h>
#include <string.h>
struct data
{
    int year,day;
    int month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
}find;
void yearmonthday()
{
    int sum,i,j;
    printf("please input the year month and day:\n");
    scanf("%d %d %d",&find.year,&i,&find.day);
    if(find.year%4==0&&find.year%100==0||find.year%400==0)
    {find.month[1]=29;}
    for(j=0;j<i;j++)
    {
        sum=sum+find.month[j];
    }
    sum=sum+find.day;
    printf("the day is %d",sum);
}
void yearday()
{  
    int i,sum=0;int month1,day1;
    printf("please input the year and day:\n");
    scanf("%d %d",&find.year,&find.day);
    if(find.year%4==0&&find.year%100==0||find.year%400==0)
    {find.month[1]=29;}
    month1=find.day/30;
    day1=find.day%30;
    printf("month=%d,day=%d",month1,day1);
   
}
void main()
{  
    int switches;
    printf("please input the case:\n");
    printf("1.please input the year,day,give your month day.\n");
    printf("2.please input the year month day give your data.\n");
    printf("plase chose (1\2):\n");
    scanf("%d",&switches);
    switch(swithes)
    {
    case 1:yearday();break;
    case 2:yearmonthday();break;
    default:printf("error!\n");break;break;
    }
   
}

第一个函数是:给定年、月、日,求天数。
第二个函数是:给定年和天数求日月,第二个函数也不会写。
各位高手帮帮忙啊!
搜索更多相关主题的帖子: 结构体 
2010-08-10 08:39
erikyo
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:2
帖 子:270
专家分:1154
注 册:2010-6-10
收藏
得分:6 
#include <stdio.h>
#include <string.h>

typedef struct data
{
    int year;
    int day;
//    int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
}find_t;

int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};        //把月份天数的数组作为全局变量更方便

void yearmonthday(find_t find)
{
    int sum,i,j;
     
    sum = 0;                    //必须先初始化,否则里面是一个无效值
    printf("please input the year month and day:\n");
    scanf("%d%d%d",&find.year,&i,&find.day);
    if(find.year%4==0&&find.year%100!=0||find.year%400==0)        //注意判断闰年的逻辑
        month[1]=29;
    for(j=0;j<i-1;j++)                    //从0开始的,必须再减1
    {
        sum=sum+month[j];
    }
    sum=sum+find.day;
    printf("the day is %d",sum);
}

void yearday(find_t find)
{  
    int i,sum=0;
    int month1,day1;

    printf("please input the year and day:\n");
    scanf("%d%d",&find.year,&find.day);
    if(find.year%4==0&&find.year%100!=0||find.year%400==0)            //判断闰年的逻辑
        month[1]=29;
    for(i = 0; ; i++)
    {
        if(find.day <= 0 )
        {
            month1 = i ;
            break;
        }
        find.day -= month[i];
    }
//    month1=find.day/30 + 1;            
//   day1=find.day%30;
    day1 = find.day + month[i-1];
    printf("month=%d,day=%d\n",month1,day1);
   
}
void main()
{  
    int switches;
    find_t find;
   
    find.day =0;
    find.year = 0;

    printf("please input the case:\n");
    printf("1.please input the year,day,give your month day.\n");
    printf("2.please input the year month day give your data.\n");
    printf("plase choose (1\2):\n");
    scanf("%d",&switches);
    switch(switches)
    {
        case 1:
            yearday(find);
            break;
        case 2:
            yearmonthday(find);
            break;
        default:
            printf("error!\n");
            break;
    }
 }

[ 本帖最后由 erikyo 于 2010-8-10 09:35 编辑 ]
2010-08-10 09:26
苗伊
该用户已被删除
收藏
得分:6 
提示: 作者被禁止或删除 内容自动屏蔽
2010-08-10 09:29
苗伊
该用户已被删除
收藏
得分:0 
提示: 作者被禁止或删除 内容自动屏蔽
2010-08-10 09:32
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:6 
程序代码:
#include <stdio.h>
#include"stdlib.h"
#include <string.h>
struct data
{
    int year,day;
    int    month[12];
}find;
struct data month[12]={31,28,31,30,31,30,31,31,30,31,30,31};
void yearmonthday()
{
    int sum,i,j;
    printf("please input the year month and day:\n");
    scanf("%d %d %d",&find.year,&i,&find.day);
    if(find.year%4==0&&find.year%100==0||find.year%400==0)
    {find.month[1]=29;}
    for(j=0;j<i;j++)
    {
        sum=sum+find.month[j];
    }
    sum=sum+find.day;
    printf("the day is %d",sum);
}
void yearday()
{ 
    int sum=0;int month1,day1;
    printf("please input the year and day:\n");
    scanf("%d %d",&find.year,&find.day);
    if(find.year%4==0&&find.year%100==0||find.year%400==0)
    {find.month[1]=29;}
    month1=find.day/30;
    day1=find.day%30;
    printf("month=%d,day=%d",month1,day1);
  
}
void main()
{ 
    int switches;
    printf("please input the case:\n");
    printf("1.please input the year,day,give your month day.\n");
    printf("2.please input the year month day give your data.\n");
    printf("plase chose (1 & 2):\n");
    scanf("%d",&switches);
    switch(switches)
    {
    case 1:yearday();break;
    case 2:yearmonthday();break;
    default:printf("error!\n");break;break;
    }
  
}
有些语法错误,帮你改好了:

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-08-10 09:48
快速回复:请各位高手帮忙看一下,哪里错了
数据加载中...
 
   



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

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