A little problem

This is a discussion on A little problem within the C Programming forums, part of the General Programming Boards category; Hello, I need little help with this. Basically what I want for the program to do for me is to ...

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    3

    A little problem

    Hello, I need little help with this. Basically what I want for the program to do for me is to show on the graphic window n number of circles with the positions i give it [a,b in my situation (that is x.y)]

    I made this and it does print out the first circle but when ever I want to enter the positions for the 2nd circle it closes


    Code:
    void circle(int a,int b);
    
    int main()
    {
      int a,b;
      int n,i;
    
    
      openwindow();
      printf("Number of circles\n");
    
      scanf("%d", &n);
    
      if(n<=0)
      {
        printf("Please enter a number higher than 0\n");
        getch();
        return 0; 
      }
      if (n>3)
      {
          printf("The number of circles is to high\n");
          getch();
    
      return 0;
      }
    
     
      printf("Enter the position of the circle/s\n");
    
    
      
      for(i=0; i<n; i++);
      {
          scanf("%d %d", &a,&b);       // Im not sure how to fix this .. what ever i try I get errors like no pointer to "i"? 
      }
    
       circle(a,b);
            
      getch();
      
      return 0;
    }
    
    void circle(int a,int b)
    {
          circle(a,b,200);
    }

    I would like if someone could give me a hint how to fix the problem I have, iv been trying to fix this for hours but i get an even more complicated problem after.

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    You should not have a semicolon at the end of for(i=0; i<n; i++);

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    3
    Thank you! I did remove the semicolon and it doesn't close anymore at the 2nd input
    How ever it prints out in the graphic window only one circle

    example what it does

    *enter the number of crircles
    ->2
    *enter the position of the circle
    x->0
    y->0
    x->100 [ it prints out only the last circle while skipping the first one ]
    y->100


    Iv been trying many things but the error list only gets flooded ...

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    Look carefully at your scope
    Code:
      for(i=0; i<n; i++)
      {
          scanf("%d %d", &a,&b);       // Im not sure how to fix this .. what ever i try I get errors like no pointer to "i"?
      }
     
      //!! this is NOT in the loop, so you only get the LAST values stored in a and b
       circle(a,b);

    > void circle(int a,int b)
    > circle(a,b,200);
    C doesn't do function overloading, so you need to be compiling this with a C++ compiler.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    3
    Thanks Salem!!!!
    I finally did it !!!

    After 2 hours [ I wish that I could function better ] of trying to do it I did it.

    I'm not sure if I could tweak the code and make it more simple but it doesn't matter because it does what I wanted it to do at the start.

    Code:
    void getcircle(int *xp,int *yp);
    void circle(int x,int y);
    
    int main()
    {
        int n;
        int x,y;
        int i=0;
        openwindow();
    
        scanf("%d",&n);
    
        while (i<n)
            {
            i++;
            getcircle(&x,&y);
            circle(x,y);
            }
        }
        
    
    
    void circle(int x, int y)
    {
        circle(x,y,200);
    }
    
    
    void getcircle(int *xp, int *yp)
    {
        scanf("%d %d", &*xp,&*yp);
    }

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    2,553
    I suggest changing this line
    Code:
    scanf("%d %d", &*xp,&*yp);
    to
    Code:
    scanf("%d %d", xp,yp);
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sleep() function problem or logic problem?
    By FernandoBasso in forum C Programming
    Replies: 7
    Last Post: 11-16-2011, 04:50 PM
  2. strcmp problem, whats the problem, i cant figure it out!
    By AvaGodess in forum C Programming
    Replies: 14
    Last Post: 10-18-2008, 06:45 PM
  3. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  4. sturct/pointer problem, and fscanf problem
    By hiphop4reel in forum C Programming
    Replies: 6
    Last Post: 07-28-2008, 09:40 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 08:14 AM

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