Thread: timer

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    1

    Question timer

    my code has a problem, and i don't know why? I'm using C.

    Code:
    int easy(int z)//EASY ROUND PROBLEM
    {
        int elapTicks;
    
         double elapMilli, elapSeconds, elapMinutes;
    
         clock_t Begin, End;             //initialize Begin and End for the timer
     
          int cells (int z){
          char sudoku_prob[Z][Y][X]={
                             {
                              {'2','5','A','6','3','B','7','9','8'},
                              {'3','4','6','2','C','1','8','7','9'},
                              {'1','D','5','4','6','9','E','8','7'},
                              {'4','7','F','5','1','8','6','3','2'},
                              {'G','9','7','3','H','6','1','2','4'},
                              {'6','3','I','8','9','7','5','4','J'},
                              {'K','8','3','7','4','L','2','1','M'},
                              {'8','N','4','1','7','2','9','5','3'},
                              {'7','1','8','O','2','3','4','P','5'},
                             },
                             };   
       Begin = clock() * CLK_TCK;    //begin the timer
       // for(int a=1; a<=10000; a++);
         sleep(1000);
          //initialization of a 3D array where array[Z][Y][X] in a 3D Cartesian plane
               int i=1,x, y,check=0;
                   for (y=0; y<Y; y++){
                            for (x=0; x<X; x++)
                            printf("%4c", sudoku_prob[z][y][x]);
                       printf("\n\n");
                   }
                   
            printf("\n\n");
            
               switch(z)
              {
                case 0:    printf("\nEnter for A: ");sudoku_prob[z][0][2]=getchar();getchar();
                           printf("Enter for B: ");sudoku_prob[z][0][5]=getchar();getchar();
                           printf("Enter for C: ");sudoku_prob[z][1][4]=getchar();getchar();
                           printf("Enter for D: ");sudoku_prob[z][2][1]=getchar();getchar();
                           printf("Enter for E: ");sudoku_prob[z][2][6]=getchar();getchar();
                           printf("Enter for F: ");sudoku_prob[z][3][2]=getchar();getchar();
                           printf("Enter for G: ");sudoku_prob[z][4][0]=getchar();getchar();
                           printf("Enter for H: ");sudoku_prob[z][4][4]=getchar();getchar();
                           printf("Enter for I: ");sudoku_prob[z][5][2]=getchar();getchar();
                           printf("Enter for J: ");sudoku_prob[z][5][8]=getchar();getchar();
                           printf("Enter for K: ");sudoku_prob[z][0][0]=getchar();getchar();
                           printf("Enter for L: ");sudoku_prob[z][6][5]=getchar();getchar();
                           printf("Enter for M: ");sudoku_prob[z][6][8]=getchar();getchar();
                           printf("Enter for O: ");sudoku_prob[z][8][3]=getchar();getchar();
                           printf("Enter for P: ");sudoku_prob[z][8][7]=getchar();getchar();
                           break;
             
             default: break;       
       }
              //Checking of answers     
              for (y=0; y<Y; y++){
                  for (x=0; x<X; x++){
                      if (sudoku_ans[z][y][x]==sudoku_prob[z][y][x])
                      check++; 
                 }
              }
                if (check==81)
                printf("\n\nAnswer Correct: Press any key to continue\n\n");
                else
                {
                printf("\n\nAnswer Incorrect: Press any key to continue\n\n");    
                check=0;
                }
            End = clock() * CLK_TCK;        //stop the timer
                return check;        
     }
        
         elapTicks = End - Begin;        //the number of ticks from Begin to End
    
         elapMilli = elapTicks/1000;     //milliseconds from Begin to End
    
         elapSeconds = elapMilli/1000;   //seconds from Begin to End
    
         elapMinutes = elapSeconds/60;   //minutes from Begin to End
    
         if(elapSeconds < 1)
    
              printf("\n\nIt took %d milliseconds.", elapMilli);
    
         else if(elapSeconds == 1)
    
              printf("\n\nIt took  1 second.");
    
         else if(elapSeconds > 1 && elapSeconds < 60)
    
              printf("\n\nIt took %d seconds.", elapSeconds);
    
         else if(elapSeconds >= 60)   
    
              printf("\n\nIt took  %d minutes.", elapMinutes);
    
      return 0;
    
     }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    What sort of problem?

    Doesn't solve soduku ?
    Doesn't time it properly ?

    Posting a snippet of uncompilable code and saying "it doesn't work" doesn't give us much to go on.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. hi-res vs. normal timer
    By MK27 in forum C Programming
    Replies: 0
    Last Post: 12-02-2009, 08:53 PM
  2. SIGALRM and timer
    By nkhambal in forum C Programming
    Replies: 1
    Last Post: 06-30-2008, 12:23 AM
  3. tic tac toe crashes :(
    By stien in forum Game Programming
    Replies: 4
    Last Post: 05-13-2007, 06:25 PM
  4. Need help with a count down timer
    By GUIPenguin in forum C# Programming
    Replies: 0
    Last Post: 07-07-2006, 04:18 PM