• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 607
  • Last Modified:

I am making a diamond by inputting the odd number between 1 to 10

I finished the code except  making it like a diamond shape. any help?

#include <iostream>
 
using namespace std;
 
 int main()
 {
	 int oddnumb;
	 do
	 {
	 cout << "type your oddnumber";
	 cin >> oddnumb;
	 } while(oddnumb>=1 && oddnumb %2 != 1 &&oddnumb <10);
	 
	int star,numb;
	 for (star =1; star<=oddnumb ; star+=2) //for 1,3,5
	{
		
		 for (numb = 1 ; numb <=star; numb++) 
		{
		
			cout<<"*";
		} cout << endl;
	 }
	
	for(star = oddnumb-2; star>=1; star-=2)
	{
		for(numb = star; numb>=1; numb--)
		{
			cout << "*";
		}
		cout << endl;
	}
 
 system("pause");
	
 }

Open in new window

0
jiwonman
Asked:
jiwonman
  • 3
  • 2
1 Solution
 
Infinity08Commented:
Well, you'll have to add a few spaces at the beginning of certain lines ... The amount of spaces you have to place is a function of the loop index numb ...

Think about it a bit, and give it a try ...
0
 
jiwonmanAuthor Commented:
got you. :) thank you.
0
 
Infinity08Commented:
May I ask why you gave a B grade ? That usually means that something was missing in the answer. If something is still not clear, then please ask about that, and I'll be happy to help you further :)
0
 
jiwonmanAuthor Commented:
I am sorry, it's my first time using this website. I didn't know what to click. I was working on different projects( trying to learn as many as I can, I am currently working on matrix multi one. it's really tough for me..). Anyways, the answer was A++. I'm sorry for that.
0
 
Infinity08Commented:
No problem ... I just wanted to make sure that you were helped ;)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now