You are using windows is it?? Give fflush(stdin) before scanf statement in the loop. It'll work
Regards, Karthikeyan M Love is magic, Rem'ber, Magic is an illusion. ________________________________ From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of shahwalishaik Sent: Thursday, March 29, 2007 4:21 AM To: [email protected] Subject: [c-prog] execution of loop unknown number of times hi there, the book i follow for C language shows that the following program is correct. but when i complie and run, it is giving odd results. the problem is it is running just once, even if 'y' is being entered for the second time. help me find the bug /*execution of a loop unknown number of times*/ main() char another='y'; int num; while(another=='y') { printf("enter a number"); scanf("%d",&num); printf("square of %d id %d", num, num*num); printf("want to enter another number? y/n"); scanf("%c",&another); } getch(); } **************** CAUTION - Disclaimer ***************** This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely for the use of the addressee(s). If you are not the intended recipient, please notify the sender by e-mail and delete the original message. Further, you are not to copy, disclose, or distribute this e-mail or its contents to any other person and any such actions are unlawful. This e-mail may contain viruses. Infosys has taken every reasonable precaution to minimize this risk, but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. Infosys reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the Infosys e-mail system. ***INFOSYS******** End of Disclaimer ********INFOSYS*** [Non-text portions of this message have been removed]
