i wrote this code can somebody check it i am not getting output please help me
program
#include<stdio.h>
#include<conio.h>
struct date
{
int day;
int month;
int year;
};
void main()
{
int i,j,k;
struct date d[356];
for (i=1;i<=1;i++)
{ {
printf("\n enter year");
scanf("%d",&d[i].year);
}
for(j=1;j<=12;j++)
{
if((j%2==0)&&(j!=2))
{
for (k=1;k<=31;k++)
scanf("%d%d",&d[j].month,&d[i].day);
}
if(j==2)
{
for (k=1;k<=28;k++)
scanf("%d%d",&d[j].month,&d[i].day);
}
if((j%2)!=0)
{
for (k=1;k<=30;k++)
scanf("%d%d",&d[j].month,&d[i].day);
}
}
}
#include <cstdio>
struct date
{
int day;
int month;
int year;
};
int main()
{
date d[356];
for ( int i = 0; i < 3; i++)
{
printf("\n enter year: ");
scanf("%d",&d[i].year);
printf("\n enter month: ");
scanf("%d",&d[i].month);
printf("\n enter day: ");
scanf("%d",&d[i].day);
}
for ( int i = 0; i < 3; i++)
{
printf("%d/%d/%d\n", d[i].day, d[i].month, d[i].year);
}
return 0;
}
Here is some example code that actually produces output. I am sorry I can't help more but it is hard to figure out what you are trying to do looking at the code you posted.
thanks for your help
i was trying to get a calender program
to store all dates in a year
and check whether the entered date is valid or not
for eg:31/2/13 is invalid
#include <iostream>
struct date
{
date (int y = 2013) : year (y) {}
int day;
int month;
int year;
bool is_leap(); // returns true for a leap year.
bool is_valid_yr(); // checks to see if years is between 1900 and 2013;
};
void populate_year_with_valid_dates ( date* d, int year);
int main()
{
constint MAX_DAYS = 366;
date* d = new date[MAX_DAYS];
int year {0};
std::cout << "enter a year: ";
std::cin >> year;
populate_year_with_valid_dates (d, year);
for ( int i = 0; i < MAX_DAYS; i++)
{
std::cout << d[i].month << '/' << d[i].day << '/' << d[i].year << std::endl;
}
return 0;
}
bool date::is_valid_yr()
{
return ( 1899 < year && year < 2014);
}
bool date::is_leap()
{
return (year % 4 == 0 && year != 2000);
}
void populate_year_with_valid_dates ( date* d, int year)
{
for(int i = 0; (d[i].month != 12 && d[i].day != 31);)
{
d[i].year = year;
if (!d[i].is_valid_yr ())
return; // ugly should throw an error
if (d[i].is_valid_yr() && d[i].is_leap())
{
for (int month = 1; month < 13; ++month)
{
switch (month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
for (int day = 1; day < 32; ++day)
{
d[i].month = month;
d[i].year = year;
d[i++].day = day;
}
break;
case 4: case 6: case 9: case 11:
for (int day = 1; day < 31; ++day)
{
d[i].year = year;
d[i].month = month;
d[i++].day = day;
}
break;
case 2:
for (int day = 1; day < 30; ++day)
{
d[i].year = year;
d[i].month = month;
d[i++].day = day;
}
break;
}
}
}else
{
for (int month = 1; month < 13; ++month)
{
switch (month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
for (int day = 1; day < 32; ++day)
{
d[i].year = year;
d[i].month = month;
d[i++].day = day;
}
break;
case 4: case 6: case 9: case 11:
for (int day = 1; day < 31; ++day)
{
d[i].year = year;
d[i].month = month;
d[i++].day = day;
}
break;
case 2:
for (int day = 1; day < 29; ++day)
{
d[i].year = year;
d[i].month = month;
d[i++].day = day;
}
break;
}
}
}
if( i > 366) break;
}
}