Thread: wats wrong with this code?

  1. #16
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    i deleted the if(a==1)
    it goes to the next function but when i entered the point..

    Code:
    void one()
    {
    int a ;
    int x[20];
    printf("\n\n\n\t\tPlayer number 1 of Team Blue has shoot the ball.");
    printf("\n\n\n\t\t\t1- one point for free throws");
    printf("\n\n\t\t\t2- two points for lay-up shot");
    printf("\n\n\t\t\t3- for three point shot");
    printf("\n\n\n\t\t\tEnter a score:   ");
    scanf("%d", &a);
    scores();
    getch();
    }
    for example i entered 1 for one point...

    the result is jumbled numbers

    Code:
    void scores()
    {clrscr();
    printf("   TEAM BLUE\t\tscores\t\t\TEAM GREEN\t\tscores");
    printf("\n\n\n\n      1\t\t\t\t\t  3");
    printf("\n\n\n      12\t\t\t\t  11");
    printf("\n\n\n      2\t\t\t\t\t  7");
    printf("\n\n\n      9\t\t\t\t\t  4");
    printf("\n\n\n      8\t\t\t\t\t  5");
    printf("\n\n\n      21\t\t\t\t  9");
    printf("\n\n\n      25\t\t\t\t\t  2");
    printf("\n\n\n      5\t\t\t\t  6");
    printf("\n\n\n      13\t\t\t\t\t  10");
    printf("\n\n\n      14\t\t\t\t\t  14");
    getch();
    }
    is there something wrong with this part?

  2. #17
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    hey there..

  3. #18
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    What is your output
    and what output do you expect
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #19
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Quote Originally Posted by vart
    What is your output
    and what output do you expect
    the output is
    like this

    TEAM BLUE SCORES TEAM GREEN(same with team blue, below is the number of plyr.
    4
    6
    8
    3
    8
    4(this is the number of the players of team blue)

    im expcting a column of scores....
    of each players...
    but before that there should be more scores to be entered by the user..

  5. #20
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    is it ok if i use array in this program?

  6. #21
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Ok, I don't understand a few things.

    Code:
       scanf("%d",&a);
       one();
    Code:
      scanf("%d", &a);
      scores();
    Both the a's are local variables. That means if you exited from the function / called another function, it will be gone. Also what is the point of using those variables in the first place if you didn't use them at all except to declare its value with scanf? If you wanted to use those variables for the next function, you should insert them as parameters for the next function (in this case the one and score function).

    Code:
    void scores()
    {clrscr();
    printf("   TEAM BLUE\t\tscores\t\t\TEAM GREEN\t\tscores");
    printf("\n\n\n\n      1\t\t\t\t\t  3");
    printf("\n\n\n      12\t\t\t\t  11");
    printf("\n\n\n      2\t\t\t\t\t  7");
    printf("\n\n\n      9\t\t\t\t\t  4");
    printf("\n\n\n      8\t\t\t\t\t  5");
    printf("\n\n\n      21\t\t\t\t  9");
    printf("\n\n\n      25\t\t\t\t\t  2");
    printf("\n\n\n      5\t\t\t\t  6");
    printf("\n\n\n      13\t\t\t\t\t  10");
    printf("\n\n\n      14\t\t\t\t\t  14");
    getch();
    }
    In this code, you printed a constant values. So you'll always get those values printed. What do you expect? I think before you started to program, you should know how a parser works.

    As for arrays, its your call. You can make an arrays of players or five variables for each of them. But what you're missing here is you didn't understand how it works in the first place.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. What's wrong with this code?
    By Luciferek in forum C++ Programming
    Replies: 4
    Last Post: 06-21-2008, 12:02 PM
  3. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  4. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM