Jul 24, 2014 at 12:06am UTC
The problem i need to solve with my code is to make a diamond that when an odd number like 5 is entered will look like this:
Please specify the width: 5
#
###
#####
###
#
and when width is even like 6:
Please specify the width: 6
##
####
######
####
##
i commented in where my code starts the odd or even loops, what i need to know is a way to skip to the odd loop if the input width is odd, thank you.
#include <iostream>
using namespace std;
int main()
{
int i,width;
cout << "enter width" <<endl;
cin>>width;
// if even
{
for( i=0;i<width;i=i+2)
{
for(int j=width;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" #";
cout<<endl;
}
for(i=width;i>0;i=i-2)
{
for(int j=width;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" #";
cout<<endl;
}
for(int i=0;i<width;i=i+2)
{
for(int j=width;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" *";
cout<<endl;
return 0;
} }
//if odd
for( i=0;i<width;i=i+2)
{
for(int j=width;j>=i;j--)
cout<<" ";
for(int k=0;k<i-1;k++)
cout<<" *";
cout<<endl;
}
for(i=width;i>=0;i=i-2)
{
for(int j=width;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" *";
cout<<endl;
}
for(int i=0;i<width;i=i+2)
{
for(int j=width;j>i;j--)
cout<<" ";
for(int k=0;k<i;k++)
cout<<" *";
cout<<endl;
return 0;
} }
Jul 24, 2014 at 12:08am UTC
diamonds should look like
Please specify the width: 6
##
####
######
####
##
Please specify the width: 5
#
###
#####
###
#
Jul 24, 2014 at 12:10am UTC
for some reason the diamonds won't show up the correct way but just imagine the lines line up to make a diamond lol
Jul 24, 2014 at 12:32am UTC
If you used code tags they would show up properly, it also makes your actual code a lot more readable. Edit your post, highlight the code and select the [<>] box under Format:
Last edited on Jul 24, 2014 at 12:33am UTC
Jul 24, 2014 at 2:04am UTC
just
1 2 3 4 5 6
if ( width % 2 == 0 ){
//..do if it's even..
}
else {
//..do if it's odd..
}
Last edited on Jul 24, 2014 at 2:04am UTC