#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    4
    Rep Power
    0

    output should be a diamond


    I am trying to figure out how to do this problem for my class lab assignment but I just keep getting stuck and upset. Iíve tried a couple of different things but they just donít even come close to doing what I would like them to do so I am not going to bother putting them up.

    Write a C++ program that inputs an integer and a character. The output should be a diamond composed of the character and extending the width specified by the integer.

    If the input integer is an even number, it should be increased to the next odd number.

    I also have this algorithm for it but it didnít help me too much since Ií am not really comprehending this stuff to well.
    Here is the algorithm:

    1. Input the character and the integer value as the program requests.
    2. Test for evenness using an if statement - round up as required.
    3. Set up integer values to count the number of spaces in each line and the number of characters printed on each line.
    4. Draw the upper half of the output - where the lines are increasing.
    4.i. For each line, output the spaces followed by the characters and then a newline.(Two separate while loops - one for the spaces and one for the characters)
    4ii Decrease the number of spaces by one
    4iii Increase the number of characters by 2
    4iv Repeat steps 4i-4iii until the output line has no spaces and the number of output
    characters is equal to the number which you initially input. ( A while loop)
    5. Cut and paste the while loops of 4. To draw the lower half of the output.
    5i. Reset the values of the various counts;
    5ii. For each line, out put the spaces followed by the characters and a newline.(Two separate while loops - one for the spaces and one for the characters)
    5iii. Increase the number of spaces by one
    5iv Dcrease the number of characters by 2
    5v. Repeat steps 5ii - 5iv until you have output a single character.(A while loop)

    Any help would be appreciated thanks.
    Last edited by holguie81; July 21st, 2003 at 11:52 AM.
  2. #2
  3. Only Human
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Florida
    Posts
    202
    Rep Power
    15
    It seems like it could be easier than that.
  4. #3
  5. Only Human
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Florida
    Posts
    202
    Rep Power
    15
    hold on, I'd like to write a program for this problem, for fun, what type of output are you using?
  6. #4
  7. Only Human
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Florida
    Posts
    202
    Rep Power
    15
    hold on, I'd like to write a program for this problem, for fun, what type of output are you using?
  8. #5
  9. Only Human
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Florida
    Posts
    202
    Rep Power
    15
    I have this so far:
    but with out a formula, its useless
    #include <iostream>
    int width=0;

    void makeDiamond(int w);

    int main (int argc, const char * argv[])
    {
    std::cout<<"What will the width of the diamond be?\n";
    std::cin>>width;
    makeDiamond(width);
    return 0;
    }

    void makeDiamond(int w)
    {
    int t=0;
    if(w % 2==0)
    {
    std::cout<<"even\n";
    w+=1;
    std::cout<<w<<'\n';
    }
    else
    {
    std::cout<<"odd\n\n";
    }
    for(int i=0;i<w;i++)
    {
    for(int k=0;k<w;k++)
    {
    //t=k/w-1;
    if(it should be a spot)
    std::cout<<"*";
    else
    std::cout<<" ";
    }
    std::cout<<"\n";
    }
    }

    I can't think of a formula, email me when you get it right. imbusfour@bellsouth.net

IMN logo majestic logo threadwatch logo seochat tools logo