Link to home
Start Free TrialLog in
Avatar of jschmuff
jschmuffFlag for United States of America

asked on

Problems with for loop to output diamond shape

I am doing this exercise to output a diamond entering a size. I have messed around with this using a odd and a positive and didn't like that way of doing it. So I have been trying to get it to enter the size of the middle of the shape. What is wrong with my for loop it displays it all wrong.


#include <iostream>
#include <iomanip>
 
using namespace std;
 
int main()
{
 
	int size;
 
	cout << "Enter a size of the middle of the diamond: ";
	cin >> size;
	cout << endl;
 
 for (int i = 1; i < size; i = i + 1)
 {
   cout << setw(size);
    for (int j = 0 ; j < i; j++)
     cout << "* ";
       cout << endl;
        --size;
        }
          for (int i = 1; i < 4; i = i + 1)
        {
                cout << setw(size + 2);
                 for (int j = 4 ; j > i; j--)
                  cout << "* ";
                   cout << endl;
                    ++size;
        }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jschmuff

ASKER

This isn't actually my homework assignment, but it is similar. Thanks though I will go over what you said and try and fix what I have.
Thanks for the help again you could have just in plain text said what was wrong with my code cause it was all messed up it was printing out a diamond but not correctly and wrong size. Instead of me figuring out what you were saying. I have bad reading comprehension.