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



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: ";
	int str = 1; //stars
	int spc = h/2; //space

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

		str = h/2+1;


return 0;

7 Years
Discussion Span
Last Post by jonsca

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?

Edited by jonsca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.