timer

Discussion in 'Meet and Greet' started by johnny12, Mar 4, 2011.

  1. johnny12

    johnny12 New Member

    Joined:
    Mar 4, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    this is my code, I dont know why it will not run perfectly?
    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;
    
     }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice