Help..Need Assistance

This is a discussion on Help..Need Assistance within the C++ Programming forums, part of the General Programming Boards category; I'm writing a C++ program that will print a diamond filled with *'s, with the size of the diamond to ...

  1. #1
    Unregistered
    Guest

    Cool Help..Need Assistance

    I'm writing a C++ program that will print a diamond filled with *'s, with the size of the diamond to be detemined by the user. This is what I'm try to get:

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


    But my code gives me this:


    *****
    ****
    ***
    **
    *
    Here's my code:

    //diamond_of_asterisks

    cout << "Enter size n (1 to 80):" <<endl;
    cin >> n;
    for (int k = 1; k <=5; ++k)
    {
    cout << setw(k) << ' ';

    for (int j =k; j <= 5; ++j;
    cout << '*';
    cout << endl;

    I can't seem to complete the diamond. Can anyone help me? Thanks!

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Neither of your examples look like a diamond. However, find a midpoint. Increase until you reach it. Decrease after.

  3. #3
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Code:
    #include <iostream>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    cout << "Enter size: 1-80" << endl;
    cin >> size;
    
    if (size > 0 && size < 80)
    {
    
    	for (int i = 0; i < size; i++)
    	{
    		int asterix = ++i;
    		for (; asterix != 0; asterix--)
    		{
    			cout << '*';
    		}
    		cout << endl;
    	}
    	
    	for (i = size; i > 0; i--)
    	{
    		int asterix = --i;
    		for (; asterix != 0; asterix--)
    		{
    			cout << '*';
    		}
    		cout << endl;
    	}
    }

  4. #4
    Unregistered
    Guest
    I really appreciate it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hello,i need assistance in completing the code
    By toader in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2009, 04:32 AM
  2. Variable Timer assistance
    By rich2852 in forum C Programming
    Replies: 2
    Last Post: 01-21-2009, 05:43 AM
  3. Any assistance would be greatly appreciated
    By iiwhitexb0iii in forum C Programming
    Replies: 18
    Last Post: 02-26-2006, 12:06 PM
  4. Need some more assistance
    By Thantos in forum Windows Programming
    Replies: 6
    Last Post: 08-14-2003, 01:13 PM
  5. Need assistance for major text base Arena RPG project
    By Ruflano in forum C++ Programming
    Replies: 0
    Last Post: 04-04-2002, 11:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21