GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Jul-2009, 09:14
fairytales247 fairytales247 is offline
New Member
 
Join Date: Jul 2009
Posts: 15
fairytales247 has a little shameless behaviour in the past
Unhappy

Why won't my DO WHILE loop loop? Please help.


Here is my program written in Dev C++. I don't know what could be the problem. Please anyone help me. I am a novice in C.

CPP / C++ / C Code:
#include<stdio.h>

int main(void){
    
    char playAgain = 'n';
    
    do{
         
         
         printf("Play againn? (Y/N)");
         scanf("%c", &playAgain);
         }while(playAgain == 'y' || playAgain == 'Y');
    
    
    
    
    }
Last edited by LuciWiz : 04-Jul-2009 at 10:22. Reason: Please insert your C code between [cpp] & [/cpp] tags
  #2  
Old 04-Jul-2009, 09:46
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 234
L7Sqr is a jewel in the roughL7Sqr is a jewel in the rough

Re: Why won't my DO WHILE loop loop? Please help.


Please use code tags.
Read up on some documentation on scanf (and family), you will find that the newline is left in the buffer when you read from stdin and that on subsequent reads you will either have to clear that or be aware of it in you comparisons.
__________________
My personal site: Utilities for text processing, debugging, testing and plotting
  #3  
Old 04-Jul-2009, 10:03
fairytales247 fairytales247 is offline
New Member
 
Join Date: Jul 2009
Posts: 15
fairytales247 has a little shameless behaviour in the past
Thumbs up

Re: Why won't my DO WHILE loop loop? Please help.


Quote:
Originally Posted by L7Sqr
Please use code tags.
Read up on some documentation on scanf (and family), you will find that the newline is left in the buffer when you read from stdin and that on subsequent reads you will either have to clear that or be aware of it in you comparisons.



Thanks man! That was so easy yet so confusing for me. Now my loop really loops. I had to do this --> scanf("\n%c", &repeatGame);
  #4  
Old 05-Jul-2009, 09:37
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Why won't my DO WHILE loop loop? Please help.


You might want to read this series on scanf. It might help.
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #5  
Old 05-Jul-2009, 15:17
fairytales247 fairytales247 is offline
New Member
 
Join Date: Jul 2009
Posts: 15
fairytales247 has a little shameless behaviour in the past
Smile

Re: Why won't my DO WHILE loop loop? Please help.


Quote:
Originally Posted by WaltP
You might want to read www.gidnetwork.com. It might help.

Great man! thanks, www.gidforums.com
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classic recursion game of 8 Queens errors BKizzle77 Java Forum 11 11-Aug-2008 01:35
Exiting an infinite loop. memmudu C++ Forum 1 31-Dec-2007 07:25
breaking an infinite loop through stdin pisuke C Programming Language 9 03-Jul-2007 21:19
Text-Based Roulette Game mfm1983 C++ Forum 5 29-Nov-2006 13:20
messy loop help please sammacs C Programming Language 6 26-Nov-2004 16:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:45.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.