delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/06/13:13:18

From: "Jason Yip" <manman AT netteens DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Pls help!!
Date: Tue, 7 Dec 1999 00:14:57 +0800
Organization: netteens.net (Hongkong Telecom IMS)
Lines: 33
Message-ID: <82gnhb$dm2$1@imsp026.netvigator.com>
NNTP-Posting-Host: olkc10b126.netvigator.com
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I wrote the following program.. I want the right answer shows "Very Good",
the wrong answer shows "No" and input again.. but why my progam like this:
1st answer always correct.. the 2nd answer always wrong...
How can I solve it? Thx a lot!!

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



- Raw text -


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