Thread: A little problem with for loop

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

    Question A little problem with for loop

    Hello guys, I have created a program that will display the array in the screen character by character with spaces in between. Now what I need to do is to display it in a diamond like pattern (1 inverted triangle and 1 normal triangle) with the first letter of the array in the middle.
    Here's my code for the array:
    Code:
    #include <iostream.h>
    #include <conio.h>
    int main()
    {
     clrscr();
     char input[100];
     int index,x=33,y=13;
     printf("Enter name: ");
     gets(input);
        for(index = 0; input[index] != '\0'; index++){
        gotoxy(x,y);
        cout<<input[index];
        x+=2;
        cout<<" ";
    }
    getch();
    return 0;
    }

  2. #2
    Informer -Adrian's Avatar
    Join Date
    Jan 2013
    Posts
    802
    This is barely C++, you might want to try your luck in the C subforum. Please get a modern compiler (they're free, so no excuses).

    Quote Originally Posted by Wikipedia
    conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C, nor is it defined by POSIX.
    ^ Stop using that too.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,509
    Are you sure you're supposed to be moving the cursor around the console like that?

    These types of problems usually rely on calculating numbers of spaces to print in order to achieve the desired shape.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very simple problem but enough difficult | Loop problem
    By Kevinphp7 in forum C++ Programming
    Replies: 13
    Last Post: 06-10-2015, 11:03 AM
  2. Glass Rod Problem and big loop problem!
    By TessaG in forum C++ Programming
    Replies: 20
    Last Post: 04-12-2015, 01:32 PM
  3. help with a loop problem
    By rambos in forum C Programming
    Replies: 3
    Last Post: 12-02-2009, 04:07 AM
  4. For Loop Problem
    By xp5 in forum C Programming
    Replies: 10
    Last Post: 09-05-2007, 04:37 PM
  5. while loop problem
    By MedicKth in forum C++ Programming
    Replies: 11
    Last Post: 10-02-2003, 09:23 PM

Tags for this Thread