Visit Jeremy's Blog.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org problem coding odd loop
 User Name Remember Me? Password
 Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.

Notices

 07-16-2004, 08:12 PM #1 shams Member   Registered: Jan 2004 Posts: 451 Rep: problem coding odd loop hi, it is suppose to be an odd loop but it is terminating after the first output,plz tell me where is the mistake: include main() { char another='y'; int num; while(another=='y') { printf("Enter a number\n"); scanf("%d",&num); printf("square of %d is %d\n",num,num*num); printf("\nWant to enter another number y/n\n"); scanf("%c",&another); }
 07-16-2004, 08:33 PM #2 kwigibo Member   Registered: Apr 2002 Location: Australia Distribution: Mandrake 8.2 Posts: 53 Rep: You are missing a right brace. I'm suprised this compiled at all. include main() { char another='y'; int num; while(another=='y') { printf("Enter a number\n"); scanf("%d",&num); printf("square of %d is %d\n",num,num*num); printf("\nWant to enter another number y/n\n"); scanf("%c",&another); } }/* missing brace here*/
 07-17-2004, 05:31 AM #3 arvind_sv Member   Registered: Oct 2002 Location: Bangalore Distribution: Gentoo Linux Posts: 96 Rep: Hi shams, Try putting a space before the %c. Make the scanf line: Code: `scanf(" %c",&another);` Arvind
 07-17-2004, 01:22 PM #4 itsme86 Senior Member   Registered: Jan 2004 Location: Oregon, USA Distribution: Slackware Posts: 1,246 Rep: scanf() leaves the \n (from the ENTER key) on the input butter. After each scanf() try adding a getchar(); to get rid of it.

 Thread Tools Search this Thread Search this Thread: Advanced Search

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is Off HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post akamaru607 Programming 12 09-01-2005 07:48 AM kingroach Linux - Software 2 02-21-2005 12:55 PM shams Programming 1 07-13-2004 07:39 PM deadlock Programming 5 09-04-2003 04:32 AM andym Linux - Newbie 0 06-05-2003 05:12 AM

LinuxQuestions.org

All times are GMT -5. The time now is 06:41 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -
 Advertisement
 My LQ
 Write for LQ LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
 Syndicate Latest Threads   LQ News Twitter: @linuxquestions Facebook: linuxquestions Google+: linuxquestions