Thread: c program problem

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    11

    c program problem

    the program compiles fine by it doesn't run as it should
    any idea what might be wrong?

    Code:
    			case 1: /*selection 1 easy*/
    				
    				i1 = rand() % 100;
    				i2 = rand() % 100;
    				i3 = rand() % 100;
    				
    				printf("\nConcentrate on the next three numbers:\n"); /*this line is printed but then clear_screen() function activates*/
    				printf("\n%d\t%d\t%d", i1, i2, i3); /*then this line is printed which should be cleared along with the one above*/
    				
    				iCurrentTime = time(NULL);
    				do 
    				{
    					iElapsedTime = time(NULL);
    				} while ( (iElapsedTime - iCurrentTime) < 4 ); /*end do while*/
    				
    				clear_screen();
    				
    				printf("\nEnter each number separated with one space: "); /*along with the numbers this line is also printed...*/
    				scanf("%d%d%d", &iResp1, &iResp2, &iResp3);
    				
    				if (iResp1 == i1 && iResp2 == i2 && iResp3 == i3)
    					
    						printf("\nCongratulations!");
    					else
    						printf("\nSorry, correct numbers were: %d %d %d", i1, i2, i3);
    					 /*end if*/

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Is this for a "bulls and cows" game or what?

    Exactly what is it doing wrong?

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > printf("\n%d\t%d\t%d", i1, i2, i3);
    Since this line does not end with a \n, you should call fflush(stdout) to ensure that the data is displayed.

    Otherwise, the output will remain buffered until after the screen has been cleared.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    well you have to remember those 3 numbers in 3 seconds
    they they "should" be cleared
    and you have to enter them correctly

    but they don't get cleared so the game is pointless

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    11
    Quote Originally Posted by Salem View Post
    > printf("\n%d\t%d\t%d", i1, i2, i3);
    Since this line does not end with a \n, you should call fflush(stdout) to ensure that the data is displayed.

    Otherwise, the output will remain buffered until after the screen has been cleared.
    thanks it worked

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Battleship Program
    By HBlakeH in forum C Programming
    Replies: 1
    Last Post: 12-05-2010, 11:13 PM
  2. im a noob at c++, do you think so?
    By belRasho in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2010, 11:02 PM
  3. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  4. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 02:38 PM