switch statement

September 10, 2010 at 07:15:25
Specs: Windows XP
good day :) we were asked to make a program about "daily horoscope"
but i can't run the program...
below is my code for CASE 1 ..


what do you think the problem with my code below..?
i cant find any mistakes.. can you help me please. ..

#include<stdio.h>
main()
{
int month,date;
clrscr();
printf("ENTER YOUR DATE OF BIRTH:\n");
printf("Month[1-12]:\n");
scanf("%d",&month);
printf("Day[1-31]:\n");
scanf("%d",&date);
switch(month)
{
case 1:
if(date>=1&&date<=19)
{
printf( "\n YOUR ZODIAC SIGN IS CAPRICORN ");
printf( "\n Your energy is focused on work today -- maybe a bit too

much so. It's a good time to get a lot done, for sure, but try to make

sure that your relationships don't suffer as a result.");
}
else if (date>=20&&date<=31)
{
printf("\n YOUR ZODIAC SIGN IS AQUARIUS ");
printf("\n Your energy is flowing freely today and it's easier than ever

for you to focus on personal issues. You don't need to close anyone

else off, but you do need to let yourself act without restraint. ”);
}
break;


See More: switch statement

Report •


#1
September 10, 2010 at 10:47:18
you didn't specify the error you're getting, but if you're spanning printf across multiple lines, then you need something like

printf("line 1 \
         line 2 \
         line 3");

or

printf("line 1"
        "line 2"
        "line 3");

If you're getting the same output regardless of the value of date, check to see if it's storing the '\n' char from month. printf("%d", date); if it's always 13, then you'll need to eat the newline before your next call to scanf.

-------------------------------------------
I have no aspiration for preaching. ;-)


Report •
Related Solutions


Ask Question