I can't tell why this piece of code wont work, but another one which I wrote does because they look exactly the same to me. Please tell me if you can see what the difference is because I cannot. I tried using the code snippet thing, but it doesn't let you copy/paste and I'm not really interested in typing both out again right now.

First one:

#include <stdio.h>
#include <stdlib.h>

main()

{

  char cYesNo = '\0';
  int iResp1 = 0;
  int iResp2 = 0;
  int iResp3 = 0;
  int iElapsedTime = 0;
  int iCurrentTime = 0;
  int iRandomNum = 0;
  int i1 = 0;
  int i2 = 0;
  int i3 = 0;
  int iCounter = 0;
  int x = 0;


  srand(time(NULL));

  printf("\nPlay a game of Concentration? (y or n): ");
  scanf("%c", &cYesNo);

  if(cYesNo == 'Y' || cYesNo == 'y') {

    i1 = rand() % 100;
    i2 = rand() % 100;
    i3 = rand() % 100;

    printf("\nConcentrate on the numbers: %d %d %d", i1, i2, i3);


    iCurrentTime = time(NULL);

    do{

      iElapsedTime = time(NULL);

    } while ( (iElapsedTime - iCurrentTime) < 3);

    for(x=0;x<25;x++); {
      printf("\n\n\n");
    }//end for

    printf("Enter each number separated with a space: ");
    scanf("%d%d%d", &iResp1, &iResp2, &iResp3);

    if(i1 == iResp1 && i2 == iResp2 && i3 == iResp3)
      printf("\nCongratulations!!!");

    else
      printf("\nSorry you didn't get it correct");

}//end if

}//end main

Second one:

  int x = 0;
  char cYesNo = '\0';
  int iResponse1 = 0;
  int iResponse2 = 0;
  int iResponse3 = 0;
  int iElapsedTime = 0;
  int iCurrentTime = 0;
  int iRandomNumber = 0;
  int i1 = 0;
  int i2 = 0;
  int i3 = 0;
  srand(time(NULL));


  printf("\nPlay a game of Concentration?\n");
  printf("\nYes or No (Y or N//y or n)\n");
  scanf("%c", &cYesNo);


  if (cYesNo == 'Y' || cYesNo == 'y') {

    i1 = rand() % 100;
    i2 = rand() % 100;
    i3 = rand() % 100;

  printf("\nConcentrate on the numbers as hard as you can!!!\n");
  printf("\n %d \t %d \t %d \n", i1, i2, i3);


  iCurrentTime = time(NULL);
  do {
    iElapsedTime = time(NULL);
    } while ( (iElapsedTime - iCurrentTime) < 3); //End do-while loop

  for(x = 0; x < 30; x ++) {  
   printf("\n");
   }


   printf("\nEnter the three numbers you saw a minute ago separated by a space each.\n");
   scanf("%d %d %d", &iResponse1, &iResponse2, &iResponse3);


   if(i1 == iResponse1 && i2 == iResponse2 && i3 == iResponse3)
     printf("\nCongratulations\n");
   else {
     printf("\nSorry you chose wrong\n");
     printf("\nThe correct numbers were:%d %d %d\n", i1, i2, i3);
     }//end else

     }//end if

}//end main

The top one doesn't pause correctly, but the bottom one will. If you can see what I missed that would be great.

Edited 4 Years Ago by pyTony: fixed your code blocks

What do you mean by doesn't pause correctly?

The first one and second one works the same
also at the first code there's a trailing semicolon on the for loop @ line 44

for(x=0;x<25;x++); {

Edited 4 Years Ago by zeroliken

hi,

i runned the codes, first it doesn't make newlines ('\n'):
(row 44)

for(x=0;x<25;x++) {
}

there is an unnecessary " ; " , so the for won't run 25times as it should,

and another thing u should put a '\n' at the end of row 33:

printf("\nConcentrate on the numbers: %d %d %d\n", i1, i2, i3);

Thank you very much. I'm new to this obviously (like you can't tell LOL) and I really don't know why adding the new line onto line 33 fixed the problem, but it did. If it wouldn't be too much to ask could you explain why it fixed my problem because I don't understand. There is a new line escape sequence at the beginning of the line so why did not having one at the end create my problem? I was under the impression that one new line sequence would be enough for each line. I have never run into this particular problem before. Again thank you for debugging that for me because I couldn't see the problem for the life of me. Good catch on line 44 too, but for my compiler it does clear the screen so maybe we just have different compilers.

This question has already been answered. Start a new discussion instead.