Thread: A solid shape diamond

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    8

    Question A solid shape diamond

    Does anyone thinks that this is a good code to create a solid shape diamond?
    I just need to do a simple diamond with a max of 9 * in the middle of the figure

    #include <stdio.h>
    int main()
    {
    int x,y,num=20;
    char symbol;

    cout << "Enter a single character>;
    cin>>symbol;
    system("cls");

    for(x = 1; x <= num / 2 + 1; x++) {
    for(y = -20; y <= num - x; y++)
    {
    cout << ' '; }

    for(y = 1; y <= 2*x - 1; y++)
    {

    cout<<symbol;
    }

    cout << end; }

    for (x= num / 2 ; x >= 1 ; x--) {
    for(y = -20; y <= num - x; y++)
    {
    cout << ' '; }

    for(y = 1; y <= 2*x- 1; y++)
    {

    cout<<symbol;
    }

    cout << end; }
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    8

    Look

    This are the instructions for the diamond.
    I did this code with a friend but I need help with it




    Create a solid diamond shape.

    You do not have to make it interactive.

    You can hard code it to use 9 asterisks at its largest (mid) point.

    Use 2 sets of nested loops. Each nest will contain two loops.

    The first nest creates the top half of the diamond and the second nest creates the bottom half.

    The two halfs are NOT mirrors of eachother. You should only have one line that is the mid point and the longest (9 asterisks) line.

    In each nest, the outer loop moves the cursor down and the inner loop moves the
    cursor accross.

    It should look something like the diamond below:

    *
    ***
    *****
    *******
    *********
    *******
    *****
    ***
    *

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Additionally, this is C++ code you have posted, not C. Rewrite using C, or post on the C++ forum.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  3. Diamond loopy
    By swgh in forum C++ Programming
    Replies: 2
    Last Post: 09-24-2007, 09:10 AM
  4. Newbie- having trouble with functions
    By bnmwad in forum C Programming
    Replies: 7
    Last Post: 02-22-2005, 04:41 PM
  5. Replies: 3
    Last Post: 04-04-2002, 05:27 PM