Hi,dear all...
Im new to C and to this discussion forum.
i hv a problem here,which is an array passing problem.
int calAge(]) doesnt work well.
i tried to look from the internet for reference but get nothing.
can u all help me to check it out?coz im not familiar at it...
thxs 1st for ur kindness....
#include <stdio.h>
#include <string.h>
#define SIZE 100
int chineseYear();
int calAge();
int i,birthYear[SIZE], birthMonth[SIZE], birthDay[SIZE],currentYear[SIZE],currentMonth[SIZE],currentDay[SIZE];
char opt,name[SIZE][20];
int years[SIZE];
int months[SIZE];
int days[SIZE];
void main()
{
for(i=0;i<SIZE;i++)
{
printf("############################################\n");
printf("##### Birthday Calculator Beta Version #####\n");
printf("############################################\n");
printf("\n");
beginning:
printf("Enter Birthday Details For User #%d? (Y/N): ",i+1);
scanf("%c",&opt);
if((opt=='Y')||(opt=='y'))
{
printf("Please enter your name: ");
scanf("%s",&name[i]);
start:
printf("Please enter current year: ");
scanf("%d",¤tYear[i]);
month:
printf("Please enter current month: ");
scanf("%d",¤tMonth[i]);
if(currentMonth[i]<1||currentMonth[i]>12)
{
printf("Wrong month input.Please enter again.\n");
goto month;
}
day:
printf("Please enter current day: ");
scanf("%d",¤tDay[i]);
if(currentDay[i]<1||currentDay[i]>31)
{
printf("Wrong day input.Please enter again.\n");
goto day;
}
printf("Please enter the year of your birth (1908-2008): ");
scanf("%d",&birthYear[i]);
if (birthYear[i]<1908||birthYear[i]>2008)
{
printf("Wrong year input.Please enter again.\n");
goto start;
}
skip:
printf("Please enter the month of your birth (1-12): ");
scanf("%d",&birthMonth[i]);
if (birthMonth[i]==1)
{
back:
printf("Please enter the day of your birth (1-31): ");
scanf("%d",&birthDay[i]);
printf("\n");
if (birthDay[i]<=19)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d January %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a CAPRICORN.\n");
printf("Your BirthStone is GARNET.\n");
printf("\n");
}
else if (birthDay[i]>19&&birthDay[i]<=31)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d January %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are an AQUARIUS.\n");
printf("Your BirthStone is GARNET.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back;
}
}
else if (birthMonth[i]==2)
{
back1:
printf("Please enter the day of your birth (1-29): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=18)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d February %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are an AQUARIUS.\n");
printf("Your BirthStone is AMETHYST.\n");
printf("\n");
}
else if (birthDay[i]>18&&birthDay[i]<=29)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d February %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a PISCES.\n");
printf("Your BirthStone is AMETHYST.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back1;
}
}
else if (birthMonth[i]==3)
{
back2:
printf("Please enter the day of your birth (1-31):\n");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=20)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d March %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a PISCES.\n");
printf("Your BirthStone is AQUAMARINE or BLOODSTONE.\n");
printf("\n");
}
else if (birthDay[i]>20&&birthDay[i]<=31)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d March %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are an ARIES.\n");
printf("Your BirthStone is AQUAMARINE or BLOODSTONE.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back2;
}
}
else if (birthMonth[i]==4)
{
back3:
printf("Please enter the day of your birth (1-30): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=19)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d April %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are an ARIES.\n");
printf("Your BirthStone is DIAMOND.\n");
printf("\n");
}
else if (birthDay[i]>19&&birthDay[i]<=30)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d April %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a TAURUS.\n");
printf("Your BirthStone is DIAMOND.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back3;
}
}
else if (birthMonth[i]==5)
{
back4:
printf("Please enter the day of your birth (1-31): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=20)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d May %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a TAURUS.\n");
printf("Your BirthStone is EMERALD.\n");
printf("\n");
}
else if (birthDay[i]>20&&birthDay[i]<=31)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d May %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a GEMINI.\n");
printf("Your BirthStone is EMERALD.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back4;
}
}
else if (birthMonth[i]==6)
{
back5:
printf("Please enter the day of your birth (1-30): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=20)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d June %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a GEMINI.\n");
printf("Your BirthStone is PEARL, ALEXANDRITE or MOONSTONE.\n");
printf("\n");
}
else if (birthDay[i]>20&&birthDay[i]<=30)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d June %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a CANCER.\n");
printf("Your BirthStone is PEARL, ALEXANDRITE or MOONSTONE.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back5;
}
}
else if (birthMonth[i]==7)
{
back6:
printf("Please enter the day of your birth (1-31): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=22)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d July %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a CANCER.\n");
printf("Your BirthStone is RUBY.\n");
printf("\n");
}
else if (birthDay[i]>22&&birthDay[i]<=30)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d July %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a LEO.\n");
printf("Your BirthStone is RUBY.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back6;
}
}
else if (birthMonth[i]==8)
{
back7:
printf("Please enter the day of your birth (1-31): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=22)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d August %d.\n",birthDay[i],birthMonth[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a LEO.\n");
printf("Your BirthStone is PERIDOT or SARDONYX.\n");
printf("\n");
}
else if (birthDay[i]>22&&birthDay[i]<=31)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d August %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a VIRGO.\n");
printf("Your BirthStone is PERIDOT or SARDONYX.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back7;
}
}
else if (birthMonth[i]==9)
{
back8:
printf("Please enter the day of your birth (1-30): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=22)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d September %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a VIRGO.\n");
printf("Your BirthStone is SAPPHIRE.\n");
printf("\n");
}
else if (birthDay[i]>22&&birthDay[i]<=30)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d September %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a LIBRA.\n");
printf("Your BirthStone is SAPPHIRE.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back8;
}
}
else if (birthMonth[i]==10)
{
back9:
printf("Please enter the day of your birth (1-31): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=22)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d October %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a LIBRA.\n");
printf("Your BirthStone is OPAL or TOURMALINE.\n");
printf("\n");
}
else if (birthDay[i]>22&&birthDay[i]<=31)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d October %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a SCORPIO.\n");
printf("Your BirthStone is OPAL or TOURMALINE.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back9;
}
}
else if (birthMonth[i]==11)
{
back10:
printf("Please enter the day of your birth (1-30): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=21)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d November %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a SCORPIO.\n");
printf("Your BirthStone is TOPAZ.\n");
printf("\n");
}
else if (birthDay[i]>21&&birthDay[i]<=30)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d November %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a SAGITARIUS.\n");
printf("Your BirthStone is TOPAZ.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back10;
}
}
else if (birthMonth[i]==12)
{
back11:
printf("Please enter the day of your birth (1-31): ");
scanf("%d",&birthDay[i]);
if (birthDay[i]<=21)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d December %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a SAGITARIUS.\n");
printf("Your BirthStone is TURQUOISE OR ZIRCON.\n");
printf("\n");
}
else if (birthDay[i]>21&&birthDay[i]<=31)
{
printf("\n%s,your birthday details:\n",name[i]);
printf("Your are born on %d December %d.\n",birthDay[i],birthYear[i]);
calAge(currentYear[i],currentMonth[i],currentDay[i],birthYear[i],birthMonth[i],birthDay[i]);
chineseYear();
printf("You are a CAPRICORN.\n");
printf("Your BirthStone is TURQUOISE OR ZIRCON.\n");
printf("\n");
}
else
{
printf("Invalid day.Please enter again.\n");
goto back11;
}
}
else
{
printf("Wrong month input.Please enter again.\n");
goto skip;
}
}
else if((opt=='N')||(opt=='n'))
{
i=SIZE;
}
else
{
printf("Invalid Input.Please try to enter again.\n");
goto beginning;
}
}
}
int chineseYear()
{
if (birthYear[i]==1992||birthYear[i]==1980||birthYear[i]==2004)
printf("You are born in the Chinese year of the MONKEY.\n");
else if (birthYear[i]==1993||birthYear[i]==1981||birthYear[i]==2005)
printf("You are born in the Chinese year of the ROOSTER.\n");
else if (birthYear[i]==1994||birthYear[i]==1982||birthYear[i]==1970||birthYear[i]==2006)
printf("You are born in the Chinese year of the DOG.\n");
else if (birthYear[i]==1995||birthYear[i]==1971||birthYear[i]==1983||birthYear[i]==2007)
printf("You are born in the Chinese year of the BOAR.\n");
else if (birthYear[i]==1996||birthYear[i]==1984||birthYear[i]==1972||birthYear[i]==2008)
printf("You are born in the Chinese year of the RAT.\n");
else if (birthYear[i]==1997||birthYear[i]==1985||birthYear[i]==1973)
printf("You are born in the Chinese year of the OX.\n");
else if (birthYear[i]==1998||birthYear[i]==1986||birthYear[i]==1974)
printf("You are born in the Chinese year of the TIGER.\n");
else if (birthYear[i]==1975||birthYear[i]==1999||birthYear[i]==1987)
printf("You are born in the Chinese year of the RABBIT.\n");
else if (birthYear[i]==1976||birthYear[i]==2000||birthYear[i]==1988)
printf("You are born in the Chinese year of the DRAGON.\n");
else if (birthYear[i]==1977||birthYear[i]==2001||birthYear[i]==1989)
printf("You are born in the Chinese year of the SNAKE.\n");
else if (birthYear[i]==2002||birthYear[i]==1978||birthYear[i]==1990)
printf("You are born in the Chinese year of the HORSE.\n");
else if (birthYear[i]==2003||birthYear[i]==1979||birthYear[i]==1991)
printf("You are born in the Chinese year of the RAM.\n");
return 0;
}
int calAge(int currentYear[],int currentMonth[],int currentDay[],int birthYear[],int birthMonth[],int birthDay[])
{
for(i=0;i<SIZE;i++)
{
years[i]=currentYear[i]-birthYear[i];
if((birthMonth[i]>currentMonth[i])||((birthMonth[i]==currentMonth[i])&&(birthDay[i]>currentDay[i])))
{
years[i]=years[i]-1;
}
months[i]=currentMonth[i]-birthMonth[i];
if(birthDay[i]>currentDay[i])
{
months[i]=months[i]-1;
}
days[i]=currentDay[i]-birthDay[i];
if(birthDay[i]>currentDay[i])
{
days[i]=(currentDay[i]+30)-birthDay[i];
}
printf("You are %d years, %d months, %d days old.\n",years[i],months[i],days[i]);
}
return 0;
}