wats wrong with this code?

This is a discussion on wats wrong with this code? within the C++ Programming forums, part of the General Programming Boards category; Code: void blue(int q,int r, int s, int t, int u) {int a; clrscr(); printf("\n\n\t\t\tThe players of Team Blue:"); printf("\n\n\n\t\t\t ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    34

    wats wrong with this code?

    Code:
    void blue(int q,int r, int s, int t, int u)
    {int a;
       clrscr();
       printf("\n\n\t\t\tThe players of Team Blue:");
       printf("\n\n\n\t\t\t   %d",q);
       printf("\n\n\n\t\t\t   %d",r);
       printf("\n\n\n\t\t\t   %d",s);
       printf("\n\n\n\t\t\t   %d",t);
       printf("\n\n\n\t\t\t   %d",u);
       printf("\n\n\n\t\t\tWhich player has the ball?");
       printf("\n\n\n\t\t\tEnter the number of the player:   ");
       scanf("%d",&a);
       if(a==1)
       one();
    getch();
    }
    void green(int v,int w, int x, int y, int z)
    {printf("%d,%d,%d,%d,%d", v,w,x,y,z);
    }
    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();
    }
    it ends with choosing the number of the player.....

  2. #2
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    I don't know. You tell me what's wrong and I'll tell you how to solve it.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Quote Originally Posted by OnionKnight
    I don't know. You tell me what's wrong and I'll tell you how to solve it.
    after choosing the number of the player...it stops...

    iy should go to function one();

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    do you have function prototypes at the top of your file(above the main function)?

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Quote Originally Posted by System_159
    do you have function prototypes at the top of your file(above the main function)?
    yes

    #include <stdio.h>
    #include<conio.h>
    #include<ctype.h>

  6. #6
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    no, those are preproccesors. What I meant was this:

    Code:
    #include <stuff>
    
    void blue(int, int, int, int, int);
    void green();
    void one();
    
    int main()
    {
      do your stuff in main;
      return(0);
    }
    
    //now write your functions
    void blue(int q,int r, int s, int t, int u)
    {int a;
       clrscr();
       printf("\n\n\t\t\tThe players of Team Blue:");
       printf("\n\n\n\t\t\t   %d",q);
       printf("\n\n\n\t\t\t   %d",r);
       printf("\n\n\n\t\t\t   %d",s);
       printf("\n\n\n\t\t\t   %d",t);
       printf("\n\n\n\t\t\t   %d",u);
       printf("\n\n\n\t\t\tWhich player has the ball?");
       printf("\n\n\n\t\t\tEnter the number of the player:   ");
       scanf("%d",&a);
       if(a==1)
       one();
    getch();
    }
    void green(int v,int w, int x, int y, int z)
    {printf("%d,%d,%d,%d,%d", v,w,x,y,z);
    }
    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();
    }

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Code:
    #include <stdio.h>
    #include<conio.h>
    #include<ctype.h>
    void new_game1();
    void blue(int q,int r, int s, int t, int u);
    void green(int v,int w, int x, int y, int z);
    void player1();
    void exit();
    void game();
    void one();
    void scores();
    void main()
    {int a,c;
    clrscr();
    printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\tLet's Play Basketball!!!");
    printf("\n\n\n\n\n\t\t\t   1 - start new game");
    printf("\n\n\t\t\t   2 - quit game");
    printf("\n\n\n\n\n                                    ");
    scanf("%d",&a);
    if(a==1)
    {new_game1();}
    else if(a==2)
    {exit();}
    else
    printf("\n\n\t\t\tYou've entered an invalid choice.");
    getch();
    }
    void new_game1()
    {
    int a,b,c,d,e,f,g,h,i,j,k,l;
    clrscr();
    printf("\tTEAM BLUE");
    printf("\n\n\n\t   1");
    printf("\n\n\n\t   12");
    printf("\n\n\n\t   2");
    printf("\n\n\n\t   9");
    printf("\n\n\n\t   8");
    printf("\n\n\n\t   21");
    printf("\n\n\n\t   25");
    printf("\n\n\n\t   5");
    printf("\n\n\n\t   13");
    printf("\n\n\n\t   14");
    printf("\n\n\t\tPlease choose 5 players from each team.");
    printf("\n\n\t\t1st player: ");
    scanf("%d", &b);
    printf("\n\n\t\t2nd player: ");
    scanf("%d", &c);
    printf("\n\n\t\t3rd player: ");
    scanf("%d", &d);
    printf("\n\n\t\t4th player: ");
    scanf("%d", &e);
    printf("\n\n\t\t5th player: ");
    scanf("%d", &f);
    printf("\n");
    printf("\tTEAM GREEN");
    printf("\n\n\n\t   3");
    printf("\n\n\n\t   11");
    printf("\n\n\n\t   7");
    printf("\n\n\n\t   4");
    printf("\n\n\n\t   5");
    printf("\n\n\n\t   9");
    printf("\n\n\n\t   2");
    printf("\n\n\n\t   6");
    printf("\n\n\n\t   10");
    printf("\n\n\n\t   14");
    printf("\n\n\t\tPlease choose 5 players from each team.");
    printf("\n\n\t\t1st player: ");
    scanf("%d", &g);
    printf("\n\n\t\t2nd player: ");
    scanf("%d", &h);
    printf("\n\n\t\t3rd player: ");
    scanf("%d", &i);
    printf("\n\n\t\t4th player: ");
    scanf("%d", &j);
    printf("\n\n\t\t5th player: ");
    scanf("%d", &k);
    printf("\n\nThe players you have chosen for Team Blue are %d,%d,%d,%d,%d",b,c,d,e,f);
    printf( "\n\nThe players you have chosen for Team Green are %d,%d,%d,%d,%d",g,h,i,j,k);
    printf("\n\n\n\n");
    printf("Let's start the game!!!");
    printf("\n\n\n\nJUMPBALL!!!");
    printf("\n\n\n\n\n\n\n\nBall possesion goes to Team?");
    printf("\n\n\t\t\t1 - Team Blue");
    printf("\n\n\t\t\t2 - Team Green");
    printf("\n\n\t\t\tEnter your choice:");
    printf("   ");
    scanf("%d", &l);
    if(l==1)
    blue(b,c,d,e,f);
    else if(l==2)
    green(g,h,i,j,k);
    }
    void exit()
    {
    printf("\n\n\t\t\tThank you for using this program");
    getch();
    }
    void blue(int q,int r, int s, int t, int u)
    {int a;
       clrscr();
       printf("\n\n\t\t\tThe players of Team Blue:");
       printf("\n\n\n\t\t\t   %d",q);
       printf("\n\n\n\t\t\t   %d",r);
       printf("\n\n\n\t\t\t   %d",s);
       printf("\n\n\n\t\t\t   %d",t);
       printf("\n\n\n\t\t\t   %d",u);
       printf("\n\n\n\t\t\tWhich player has the ball?");
       printf("\n\n\n\t\t\tEnter the number of the player:   ");
       scanf("%d",&a);
       if(a==1)
       one();
    getch();
    }
    void green(int v,int w, int x, int y, int z)
    {printf("%d,%d,%d,%d,%d", v,w,x,y,z);
    }
    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();
    }
    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();
    }
    threept(int a)
    {int c;
    c=a+3;
    return c;
    }
    onept(int a)
    {int c;
    c=a+1;
    return c;
    }
    twopt(int a)
    {int c;
    c=a+2;
    return c;
    }
    this is the whole code.....

    actually we'll have to include the highest score.. what team got the highest score so that they will declared as the winner.. also the mVP player...

  8. #8
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    iy should go to function one();
    After I fixed some warnings from the compiler - it goes there...
    So the problem (besides the void main and missing indentetion) is somewhere else.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  9. #9
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Quote Originally Posted by vart
    After I fixed some warnings from the compiler - it goes there...
    So the problem (besides the void main and missing indentetion) is somewhere else.
    what part of program?
    awts....i dont know how to fix it up coz i dont have enough knowledge bout C.

  10. #10
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    what part of program?
    The right question here is
    What problem do you have? Because the problem you noted actually does not exist.
    And this question only you can answer.
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  11. #11
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Quote Originally Posted by vart
    The right question here is
    What problem do you have? Because the problem you noted actually does not exist.
    And this question only you can answer.
    after i entered the number of the player
    Code:
    printf("\n\n\n\t\t\tEnter the number of the player:   ");
       scanf("%d",&a);
       if(a==1)
       one();
    getch();
    }
    its here right?

    then...it stops there....
    after i entered for example player number 9...
    it goes in the next line.. then after i pressed any key...it goes back to the compiler...

  12. #12
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    it should
    because you ask to run function one() only when a == 1
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  13. #13
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Quote Originally Posted by vart
    it should
    because you ask to run function one() only when a == 1
    what if i delete the a==1?

  14. #14
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    what if i delete the a==1?
    what if you delete it?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  15. #15
    Registered User
    Join Date
    Dec 2006
    Posts
    34
    Quote Originally Posted by vart
    what if you delete it?
    ill try...i dont know what will happen next...

    do you know how to tabulate all the scores that user had input?

Page 1 of 2 12 LastLast
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, 09: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, 05: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

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