Thread: Need to use gotoxy() inside a nested for loop

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    13

    Question Need to use gotoxy() inside a nested for loop

    Hello guys, I have created a program that will accept left and top (x,y) it will determine where the cursor will start printing "*". My problem is if i input 2 in the left variable it will print the 1st column starting with the left or X coordinate. The next row however wont start just below the 1st * of the 1st column. I need to put the
    Code:
    gotoxy(left,top)
    inside the for loop and increment the top so that it will start just below the previous column.

    Code:
     #include <conio.h>
    #include <iostream.h>
    #include <stdio.h>
    
    int main()
    {
    int mat[10][10],left,top,row,col;
    clrscr();
    cout<<"\nEnter value for left: ";
    cin>>left;
    cout<<"\nEnter value for top: ";
    cin>>top;
    cout<<"\nEnter value for Row: ";
    cin>>row;
    cout<<"\nEnter value for Colun: ";
    cin>>col;
    clrscr();
    gotoxy(left,top);
    for(int i= 0; i < row; ++i)
    {
       for(int j = 0; j< col ; ++j)
       {
    
    printf("* ",mat[row][col]);
       }
    printf("\n");
    }
    
    getch();
    return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Oct 2015
    Posts
    13
    Nevermind, solved it.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,626
    Post your solution so others with a similar problem can learn.
    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.

  4. #4
    Registered User
    Join Date
    Oct 2015
    Posts
    13
    Code:
     for(int i= 0; i < row; ++i)
    {
    top++;
    gotoxy(left,top);
       for(int j = 0; j< col ; ++j)
       {
    
    printf("* ",mat[row][col]);
    
     }
    printf("\n");
    }
    i just added top++ inside the for loop

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gotoxy breaking the FOR loop
    By Amitesh93 in forum C Programming
    Replies: 4
    Last Post: 06-04-2013, 07:32 AM
  2. Gotoxy along with FOR Loop
    By HellHands in forum C Programming
    Replies: 8
    Last Post: 02-07-2012, 11:05 AM
  3. Gotoxy along with FOR Loop
    By HellHands in forum C++ Programming
    Replies: 3
    Last Post: 02-07-2012, 07:21 AM
  4. Nested while loop inside for loop
    By Sonny in forum C Programming
    Replies: 71
    Last Post: 07-31-2011, 08:38 PM
  5. A nested if inside the switch
    By Extropian in forum C Programming
    Replies: 20
    Last Post: 08-15-2005, 01:23 AM

Tags for this Thread