My assignment is to write a program that produces a diamond when the user inputs an integer, if the integer is even it should be increased to the next odd number.
if the number is 7, it should print:
___*
__***
_*****
*******
_*****
__***
___*
(Without the underscores.)
So far I am able to produce the following output with the code I have written:
Enter number: 7
3
*
**
***
Press any key to continue
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int n;
cout<<"Enter number: ";
cin>>n;
cout<<n/2<<endl<<endl;
for(int i=0; i<=n/2; i++){
cout<<" ";
for(int st=1; st<=i; st++)
{
cout<<"*";
}
cout<<endl;
}
return 0;
}
This is an assignment on nested loops, so we're supposed to use 4 for loops. I suspect that there's going to be 2 pairs of nested for loops. Can anyone help me out?