From: "Jason Yip" Newsgroups: comp.os.msdos.djgpp Subject: "-1" cannot quite the prog.. Date: Tue, 7 Dec 1999 23:37:24 +0800 Organization: netteens.net (Hongkong Telecom IMS) Lines: 39 Message-ID: <82j9n0$bi8$1@imsp026.netvigator.com> NNTP-Posting-Host: olkc10b118.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 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 #include #include 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; }