Click here to Skip to main content
15,913,758 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: SDI ,Terrible. Pin
grassrootkit20-Feb-09 5:26
grassrootkit20-Feb-09 5:26 
AnswerRe: SDI ,Terrible. Pin
grassrootkit20-Feb-09 5:28
grassrootkit20-Feb-09 5:28 
GeneralRe: SDI ,Terrible. Pin
David Crow20-Feb-09 5:33
David Crow20-Feb-09 5:33 
GeneralRe: SDI ,Terrible. Pin
grassrootkit20-Feb-09 18:47
grassrootkit20-Feb-09 18:47 
GeneralRe: SDI ,Terrible. Pin
grassrootkit20-Feb-09 19:03
grassrootkit20-Feb-09 19:03 
GeneralRe: SDI ,Terrible. Pin
David Crow21-Feb-09 14:04
David Crow21-Feb-09 14:04 
QuestionC CODE HELP!!! Pin
lincoding20-Feb-09 3:23
lincoding20-Feb-09 3:23 
AnswerRe: C CODE HELP!!! (PROPERLY FORMATTED!!!!!) Pin
Iain Clarke, Warrior Programmer20-Feb-09 4:00
Iain Clarke, Warrior Programmer20-Feb-09 4:00 
Note that I (a) read the forum guidelines about using the pre tag, (b) formatted your code so it is readable, and (c) have located my Caps Lock key.
I did however use multiple exclamation marks so it still looks like I was mad while typing.

main()
{           
  char ans;
  printf("\n Do you want to play?(Y/N) ");    // <-- the \n should be at the end, probably. Up to you.
	
  scanf("%c",&ans);
  if ((ans == 'y'))                            //  <-- why the double brackets?
  {
    if (ans == 'y')                            //  <-- haven't you just tested this two lines up?
    {
      printf("\n Ok lets play! Press (Y) ");
    }
  }
	
  /*THIS IS WHERE IT SKIPS*/
  scanf("%c",&ans);
  if ((ans == 'y'))
  {   
    if (ans == 'y')                            // <-- You reeeeeeeally want to be sure they press Y!
    { 
      printf("\n Press (Y) again ");
    }
  }
	
  /* AND DOES THIS INSTEAD - Confused */
  scanf("%c",&ans);
  if ((ans == 'y'))
  {
    if ((ans == 'y'))
    { 
      printf("\n Program Success!\n\n");
    }
  }

  return 0;
} 


Without running your program one line at a time, I don't know why it's passing over the middle test. But you are testing everything twice, which makes me suspicious.

I would single step through, and have a close look at the value of ans each time.
I would not be surprised to find that it is 'y' the first time it is called, and '\n' the second time, because you pressed Y and then pressed return.

But that's your voyage of discovery. Good luck!

Iain.

Codeproject MVP for C++, I can't believe it's for my lounge posts...

GeneralRe: C CODE HELP!!! (PROPERLY FORMATTED!!!!!) Pin
lincoding20-Feb-09 4:51
lincoding20-Feb-09 4:51 
GeneralRe: C CODE HELP!!! (PROPERLY FORMATTED!!!!!) Pin
Iain Clarke, Warrior Programmer20-Feb-09 5:10
Iain Clarke, Warrior Programmer20-Feb-09 5:10 
GeneralRe: C CODE HELP!!! (PROPERLY FORMATTED!!!!!) Pin
Luc Pattyn20-Feb-09 5:19
sitebuilderLuc Pattyn20-Feb-09 5:19 
GeneralRe: C CODE HELP!!! (PROPERLY FORMATTED!!!!!) Pin
CPallini20-Feb-09 6:22
mveCPallini20-Feb-09 6:22 
QuestionRe: C CODE HELP!!! Pin
David Crow20-Feb-09 5:17
David Crow20-Feb-09 5:17 
AnswerRe: C CODE HELP!!! Pin
Jonathan Davies20-Feb-09 5:33
Jonathan Davies20-Feb-09 5:33 
AnswerRe: C CODE HELP!!! Pin
Code-o-mat20-Feb-09 5:56
Code-o-mat20-Feb-09 5:56 
QuestionDialog box is looks like hang. [modified] Pin
Le@rner20-Feb-09 1:52
Le@rner20-Feb-09 1:52 
AnswerRe: Dialog box is looks like hang. Pin
CPallini20-Feb-09 2:01
mveCPallini20-Feb-09 2:01 
GeneralRe: Dialog box is looks like hang. Pin
Le@rner20-Feb-09 17:57
Le@rner20-Feb-09 17:57 
GeneralRe: Dialog box is looks like hang. Pin
CPallini21-Feb-09 5:31
mveCPallini21-Feb-09 5:31 
Questiona qustion Pin
Archy_Yu20-Feb-09 1:11
Archy_Yu20-Feb-09 1:11 
AnswerRe: a qustion Pin
Nishad S20-Feb-09 1:43
Nishad S20-Feb-09 1:43 
GeneralRe: a qustion Pin
CPallini20-Feb-09 1:47
mveCPallini20-Feb-09 1:47 
GeneralRe: a qustion Pin
Nishad S20-Feb-09 2:05
Nishad S20-Feb-09 2:05 
GeneralRe: a qustion Pin
Archy_Yu20-Feb-09 13:05
Archy_Yu20-Feb-09 13:05 
GeneralRe: a qustion Pin
Nishad S20-Feb-09 18:21
Nishad S20-Feb-09 18:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.