Mail Archives: djgpp/1998/07/16/15:15:40
WillB wrote:
>
> I can't get this program to work. It is supposed to ask for name, age, and
> month of birth, then print the name and age, then if else the different
> months to choose the correct description of their horoscope. DJGPP tells me
> january is undeclared and febuary is undeclared. What am I doing wrong. I'm
> sorry if I have done something stupid- but I am new to this. Program is
> below (in C)
>
> Thanks in advance,
> Will
> exSite DOT Website AT btinternet DOT com
>
> *************************************PROGRAM*******************
>
> #include <stdio.h>
>
> int main()
> {
>
> char name[20];
> short age;
> char month[10];
>
> printf("hello, and welcome to my little program\n");
>
> printf("Please enter your name...\n");
> scanf("%s", name);
> printf("Please enter your age...\n");
> scanf("%i", &age);
> printf("please enter the month you were born in lowercase..\n");
> scanf("%s", month);
>
> printf("So your name is %s and your age is %i \n", name, age);
>
> if(month==january)
> printf("And your star sign is Capricorn(22 Dec-20 Jan) or
> Aquarius(21 Jan-19 Feb)\n");
> else if(month==february)
> pritnf("And your star sign is Aquarius(21 Jan-19 Feb) or Pisces(20
> Feb-20 Mar)\n");
> else
> printf("And I can't be arsed to write 'if else's' to find your star
> sign - try January or February\n");
>
> printf("Thank you - and goodbye....\n");
>
> return 0;
> }
First, by saying if(month==january)you are comparing to variables. if(month=="january") would be correct,
but to compare strings you have to use
if (strcmp("january",month)){
instead. Also, you have spelt prinf wrong on the february bit, but that is just a little mistake.
Hope it works now, but I haven't checked it.
Peter Allen
- Raw text -