Reverse order printing

This is a discussion on Reverse order printing within the C Programming forums, part of the General Programming Boards category; I put this up earlier, but my code is way different now and I can't figure out why mine prints ...

  1. #1
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463

    Reverse order printing

    I put this up earlier, but my code is way different now and I can't figure out why mine prints in the reverse order. I just want to know why it prints the way it does, just to get past phase 1 and move on to the next bit of the game.

    Code:
    //ASSIGNMENT 1, TENNIS GAME
    // MORE FUNCTIONS TO BE ADDED AS PROGRAM PROGRESSES                                                                               19/08/07 Version
    
    #include <stdio.h>
    
    #define PRINT 0       
    #define DEUCE 1
        
    
    int scoreA = 0;  //Declaration of global variables
    int scoreB = 0;
    int gameA = 0;
    int gameB = 0;
    
    int scoreFunct(char c, char team, int gameA, int gameB);     // THIS FUNCTION DOES THE SCORE CALCULATION
    void printFunct(int scoreA, int scoreB, char c, char team, int gameA, int gameB);   //THIS FUNCTION DOES THE MAJOR PRINTING(SCORES,GAMES etc.)
    
    int main (int argc, char **argv){
      
      char team;
      char c;
      int cnt = 0;//counting variable for while loop
      
      while(((team = getchar()) != EOF) && (cnt < 1)){                         //This loop here ends after 1 letter is detected
        if((team == 'A') || (team == 'a') || (team == 'B') || (team == 'b')){
          scoreFunct(c,team,gameA,gameB);
        }
      cnt++;
      }    
          
      return(0);
    }
    
    //THIS IS THE SCORING FUNCTION
    
    int scoreFunct(char c, char team, int gameA, int gameB){
      
      while((c = getchar()) != EOF){
    
        if (c == 'S'){
          printFunct(scoreA,scoreB,c,team,gameA,gameB);
          return(PRINT);
        }  
            
        else if(c == 'B'){
          if(scoreB < 30){
            scoreB+=15;
          }  
          else if(scoreB == 30){
            scoreB+=10;
          }
          else if(scoreB == 40){
            if(team == 65){
              gameB = gameB + 1;
              scoreB = scoreB - scoreB;  //Since scoreB is a global variable, we need to reset it to 0 after the game to start the new score for next game
              scoreA = scoreA - scoreA;
              team = 65 + 1;
            }
            else if(team == 66){
              gameB = gameB + 1;
              scoreB = scoreB - scoreB;
              scoreA = scoreA - scoreA;
              team = 66 - 1;
            }
          }
        }      
              
        else if(c == 'A'){
          if(scoreA < 30){
            scoreA+=15;
          }  
          else if(scoreA == 30){
            scoreA+=10;
          }
          else if(scoreA == 40){
            if(team == 65){
              gameA = gameA + 1;
              scoreA = scoreA - scoreA;  //Since scoreA is a global variable, we need to reset it to 0 after the game to start the new score for next game
              scoreB = scoreB - scoreB;
              team = 65 + 1;
            }
            else if(team == 66){
              gameA = gameA + 1;
              scoreA = scoreA - scoreA;
              scoreB = scoreB - scoreB;
              team = 66 - 1;
            }
          } 
        }
      }           
            
      return(0);
    }
    
    //THIS IS THE PRINTING FUNCTION
    
    void printFunct(int scoreA, int scoreB, char c, char team, int gameA, int gameB){
      
      
      if(scoreFunct(c,team,gameA,gameB) == PRINT){
        if((scoreA == 0) && (scoreB == 0)){
          printf("Team &#37;c to serve:\n", team);
          printf("%d-%d\n",gameA,gameB);
          printf("Love-All\n");
          printf("\n");
        } 
        else if((scoreA < 40) && (scoreB < 40)){
          if(team == 65){
            printf("Team %c to serve:\n", team);
            printf("%d-%d\n",gameA,gameB);
            printf("%d-%d\n", scoreA, scoreB);
            printf("\n");
          }
          else if(team == 66){
            printf("Team %c to serve:\n", team);
            printf("%d-%d\n",gameA,gameB);
            printf("%d-%d\n", scoreB, scoreA);
            printf("\n");
          }
        }
        else if((scoreA == 40) || (scoreB == 40)){
          if((scoreA == 40) && (scoreB == 40)){
            printf("Team %c to serve:\n", team);
            printf("%d-%d\n",gameA,gameB);
            printf("DEUCE\n");
            printf("\n");
          }
          else{
            if(team == 65){
              printf("Team %c to serve:\n", team);
              printf("%d-%d\n",gameA,gameB);
              printf("%d-%d\n", scoreA, scoreB);
              printf("\n");
            }
            else if(team == 66){
              printf("Team %c to serve:\n", team);
              printf("%d-%d\n",gameA,gameB);
              printf("%d-%d\n", scoreB, scoreA);
              printf("\n");
            }
          }
        }        
        else if((scoreA == 0) && (scoreB > 0)){
          if(team == 65){
            printf("Team %c to serve:\n", team);
            printf("%d-%d\n",gameA,gameB);
            printf("Love-%d\n",scoreB);
            printf("\n");
          }
          else if(team == 66){
            printf("Team %c to serve:\n", team);
            printf("%d-%d\n",gameA,gameB);
            printf("%d-Love\n",scoreB);
            printf("\n");
          }
        }    
        else if((scoreA > 0) && (scoreB == 0)){
          if(team == 65){
            printf("Team %c to serve:\n", team);
            printf("%d-%d\n",gameA,gameB);
            printf("%d-Love\n",scoreA);
            printf("\n");
          }
          else if(team == 66){
            printf("Team %c to serve:\n", team);
            printf("%d-%d\n",gameA,gameB);
            printf("Love-%d\n",scoreA);
            printf("\n");
          }
        }
      }    
    }

  2. #2
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i want to print my linked list in the reverse order please help
    By raghu_equinox in forum C Programming
    Replies: 9
    Last Post: 10-14-2006, 01:45 AM
  2. gethostbyaddr() reverse lookups failing (???)
    By Uncle Rico in forum C Programming
    Replies: 9
    Last Post: 08-19-2005, 10:22 AM
  3. Divide and Conquer: array in the reverse order
    By Steamer in forum C Programming
    Replies: 11
    Last Post: 03-08-2004, 07:31 PM
  4. Printing name in reverse order and in caps
    By Guti14 in forum C++ Programming
    Replies: 1
    Last Post: 08-17-2003, 08:02 AM
  5. Printing String in reverse order
    By ling in forum C Programming
    Replies: 14
    Last Post: 10-18-2001, 10:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21