# Thread: need help with C im new to programming

1. ## need help with C im new to programming

i wanted to write a simple program that tell the user zodiac sign and his life path number , the problem is even when given wrong birth date it keep writing the life path number , i am using Euclidean division
exmp 12/02/1999

day 12 = 1 + 2 = 3
month 2 +0= 2
year 1999 = 1 + 9 + 9 + 9 =28= 2 + 8 = 10=1 + 0 = 1

total day +month + year
2 + 3 + 1 = 6

Life Path Number is 6

Code:

Code:
```#include <stdio.h>
#include <stdlib.h>

int main()
{
int year,xmd,xmd1,xy,lpn,lpn1,lpn2,xt,x,xt2,xd,xm,m,day,q1,q2,r,q3,q4,dr ;

scanf("%d", &m);
scanf("%d", &day);
scanf("%d", &year);
if(( year<=1920 ) || (year>=2020  ))
{
printf("Invalid Year of Birth \n");
}

else if( (m == 12 && day >= 22) || (m == 1 && day <= 19) )
{
}
else if( (m == 1 && day >= 20) || (m == 2 && day <= 17) )
{
}
else if( (m == 2 && day >= 18) || (m == 3 && day <= 19) )
{
}
else if( (m == 3 && day >= 20) || (m == 4 && day <= 19) )
{
}
else if( (m == 4 && day >= 20) || (m == 5 && day <= 20) )
{
}
else if( (m == 5 && day >= 21) || (m == 6 && day <= 20) )
{
}
else if( (m == 6 && day >= 21) || (m == 7 && day <= 22) )
{
}
else if( (m == 7 && day >= 23) || (m == 8 && day <= 22) )
{
}
else if( (m == 8 && day >= 23) || (m == 9 && day <= 22) )
{
}
else if( (m == 9 && day >= 23) || (m == 10 && day <= 22) )
{
}
else if( (m == 10 && day >= 23) || (m == 11 && day <= 21) )
{
}
else if( (m == 11 && day >= 22) || (m == 12 && day <= 21) )
{

}
else
{
printf("Invalid Birth date entered\n");
}

q1=year/1000;
r=year%1000;
q2=r/100;
r=r%100;
q3=r/10;
r=r%10;
q4=r;
xy=q1+q2+q3+q4;

if (m >= 10 && day >= 10)
{

x=m/10;
xm=m%10;
xd=day/10;
dr=day%10;
x=dr+xd+xm+x;
}
else { x=m;

xd=day;
x=xd+m;

}
if (x >= 10)
{
xmd=x/10;
xmd1=x%10;
x=xmd+xmd1;
}

if (xy >= 10 )
{
xt=xy/10;
xt2=xy%10;
xy=xt+xt2;
}

lpn=xy+x;

if (lpn >= 10 )
{

lpn1=lpn/10;
lpn2=lpn%10;
lpn=lpn1+lpn2;
}

printf("your life path is " "%d\n",lpn) ;

return 0;

}``` 2. Can you show us your sample output when the problem occurs?

I suspect you want to 'loop' around when getting the date, while the day, month or year is invalid.

Also this might be an easier way to calculate 'lpn' given year, month and day:
Code:
```int digits = year*10000+month*100+day;
while(digits > 10) {
digits = (digits/10) + digits%10;
}
lpn = digits;```
Oh, and because you are using 'else', you don't need half of the date tests... 3. ## output

the first is correct but in the second one as you can see it say Invalid Birth date entered but it show the life path number
i need to test (use if function )with all the dates cause every date have different zodiac sign

the program it self is correct but only the loop , it need to stop at the last else if all the conditions are false and not showing the msg " your life path is ... "
one last thing how can i optimize it , maybe spread it in other files by functions and call them to the main one
thanks for the help i really appreciate it 4. Do you need something like this?

Code:
```printf("Enter your birth year\n");
scanf("%d", &year);
while(year<=1920 || year>=2020) {
printf("Invalid Year of Birth \n");
scanf("%d", &year);
}```
(Example is just for getting the year) 5. Originally Posted by hamster_nz Do you need something like this?

Code:
```printf("Enter your birth year\n");
scanf("%d", &year);
while(year<=1920 || year>=2020) {
printf("Invalid Year of Birth \n");
scanf("%d", &year);
}```
(Example is just for getting the year)

thank you so much it helped for the year , still need the same after verifying the month and the day are not equal to all of the conditions

thank you, much respect 6. Code:
```#include <stdio.h>

struct {
const char *month;
const char *zodiac;
int         ends;
} Data[] = {
{ "January",   "Capricorn",   19 },
{ "February",  "Aquarius",    19 },
{ "March",     "Pisces",      20 },
{ "April",     "Aries",       20 },
{ "May",       "Taurus",      20 },
{ "June",      "Gemini",      20 },
{ "July",      "Cancer",      22 },
{ "August",    "Leo",         22 },
{ "September", "Virgo",       22 },
{ "October",   "Libra",       22 },
{ "November",  "Scorpio",     22 },
{ "December",  "Sagittarius", 21 }
};

int main() {
int y, m, d;
printf("y: "); scanf("%d", &y);
printf("m: "); scanf("%d", &m);
printf("d: "); scanf("%d", &d);

printf("%s %d, %d\n", Data[m - 1].month, d, y);

int z = (m - (d <= Data[m - 1].ends)) % 12;
printf("Your Zodiac Sign is %s.\n", Data[z].zodiac);

int lp = y + m + d;
lp = (lp % 9 ? lp % 9 : 9);
printf("Your life path is " "%d.\n", lp);

return 0;
}``` 7. thanks i really appreciate it , but can i keep the function the way i did it ? thanks again just small modification  Popular pages Recent additions birth, c programing, day, horoscope, life path number 