www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/16/15:15:40

From: Allens <allen DOT asjp AT cableol DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: <NEWBIE> why does this not work?
Date: Thu, 16 Jul 1998 19:06:01 +0100
Organization: Cable Online
Lines: 57
Message-ID: <35AE4109.65A2@cableol.co.uk>
References: <6olca3$8ps$1 AT mendelevium DOT btinternet DOT com>
NNTP-Posting-Host: 194.168.181.11
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019