Hey guys,
I justs started this code to make a diamond with stars (*), but I get confused how to print the spaces that I need, I don't know if you understant what I'm trying to say. It is something like this:

Prompt the user to enter (odd) height (of a diamond) and outputs the following:

Example height = 7

Output:

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

and this is the code I'm working on, it is very basic but I'm struggling finding the mistakes and that is just the top part of the diamond:

#include <iostream>
#include <string>

using namespace std;


int main(){

	int h; //height
	cout<<"Enter any positive number: ";
	cin>>h;
	
	int str = 1; //stars
	int spc = h/2; //space

	for(int k=0; k<str; k++){
		cout<<"*"<<endl;
		for(int i=0; i<spc; i++)
			cout<<" "<<endl;

		str = h/2+1;
		spc--;

	}

system("PAUSE");
return 0;

}

Don't use the endl as that's moving each * onto it's own line. You have the right idea with 2 for loops. Are you prevented from adding a third to step through each line of the diamond? You might use some if statements, placed strategically to decide which of the top or bottom you are printing and how to change the spacing. The best advice I can give you is try some different things -- you said you're close to printing the top of it, can you print the bottom of it by itself?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.