July 21st, 2003, 12:39 PM
Join Date: Jul 2003
Time spent in forums: < 1 sec
Reputation 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 12:52 PM.