Thread: A little problem

  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,834
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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
    4,183
    I suggest changing this line
    Code:
    scanf("%d %d", &*xp,&*yp);
    to
    Code:
    scanf("%d %d", xp,yp);
    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

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, 05: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, 09:14 AM