www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/08/17:43:06

From: "Anes Hadzic" <a DOT hadzic AT bih DOT net DOT ba>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: "-1" cannot quite the prog..
Date: Wed, 8 Dec 1999 21:42:58 +0100
Organization: BIHnet News Server
Lines: 87
Message-ID: <82mjrm$qkh5@ns4.bih.net.ba>
References: <82j9n0$bi8$1 AT imsp026 DOT netvigator DOT com>
NNTP-Posting-Host: dialup1-ppp225.bih.net.ba
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2014.211
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Jason Yip <manman AT netteens DOT net> wrote in message
news:82j9n0$bi8$1 AT imsp026 DOT netvigator DOT com...
> I wrote this prog and expect it can be quited by entering -1...
> however it shows wrong if I enter "-1"...
> What's more, when I enter a wrong answer.. the answer will never be
correct
> again...
> I wonder why it acts like this...
> Can anyone helps me? Thx..
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
> main ()
> {
> int ans,h,a,b;
> printf("Enter -1 to end\n");
> do{
> srand(time(NULL));
> a=1+(rand()%9);
> b=1+(rand()%9);
> printf("How much is %d times %d? ",a,b);
> ans=a*b;
> scanf("%d",&h);
>         if (ans == h || h != -1)
>         printf("Very Good!\n");
>         else
>         if (ans != h || h != -1){
>         do{{
>         printf("No. Please try again.\n");
>         printf("? ");
>         scanf("%d",&h);}
>         if (ans == h || h != -1)
>         printf("Very Good!\n");} while (ans != h || h != -1);
>         }} while (h != -1);
>         if (h == -1)
>  printf("That's all for now. Bye.");
> return 0;
> }
>
>
>

>         if (ans != h || h != -1){
>         do{{
>         printf("No. Please try again.\n"); ...
...
> however it shows wrong if I enter "-1"...

... mean: if ans!=h OR h!=-1. It's allways true.

 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 main ()
 {
   int ans,h,a,b;
   printf("Enter -1 to end\n");
   srand(time(NULL));
   for (;;) /* forever */
   {
     a=1+(rand()%9);
     b=1+(rand()%9);
     printf("How much is %d times %d? ",a,b);
     ans=a*b;
     for (;;)
      {
        scanf("%d",&h);
        if (h==-1) /* terminate */
        {
          printf("\nThat's all for now. Bye.");
         exit (0);
        }
        if (ans==h )
        {
          printf("Very Good!\n");
          break;
        }
       else
         printf("No. Please try again.\n");
     }
  }
}



- Raw text -


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