-
How do I make a Diamond?
Hello. I was wonder, as an aspiring C++ programmer, how one would make a diamond
dependant on user input.
For example, if the user inputs
Width: 5
This should appear
*
***
*****
***
*
Can you help? Thanks for your time, Bentley
-
Re: How do I make a Diamond?
How about
--
Randy Charles Morin
http://www.kbcafe.com
Feel free to contact me by private email or messenger
morin_randy@hotmail.com
randy@kbcafe.com
#include <iostream>
#pragma argsused
int main(int argc, char* argv[])
{
int k = 0;
std::cout << "Width?" << std::endl;
std::cin >> k;
for (int i = 0; i < k; i++)
{
for (int j = 0; j < k; j++)
{
if ( !(::abs(i-j)>k/2) && !((i+j)<k/2)
&& !((i+j)>(k+k/2-1) ) )
{
std::cout << "*";
}
else
{
std::cout << " ";
};
};
std::cout << std::endl;
}
return 0;
}
"Bentley" <crashman2011@aol.com> wrote in message news:3c582ccc$1@10.1.10.29...
>
> Hello. I was wonder, as an aspiring C++ programmer, how one would make a diamond
> dependant on user input.
>
> For example, if the user inputs
> Width: 5
> This should appear
>
> *
> ***
> *****
> ***
> *
>
> Can you help? Thanks for your time, Bentley
-
Re: How do I make a Diamond?
"Bentley" <crashman2011@aol.com> wrote:
>
>Hello. I was wonder, as an aspiring C++ programmer, how one would make a
diamond
>dependant on user input.
>
>For example, if the user inputs
>Width: 5
>This should appear
>
> *
> ***
> *****
> ***
> *
>
>Can you help? Thanks for your time, Bentley
---------------------------------------------------------------------------
//input the width of the diamond and the character that you want to be used
//you can modify it as u wish, i worte this program when i was begining c++
#include <iostream>
#include <iomanip>
using namespace std;
void shape1(int n, char p, char e);
void shape2(int n, char p, char e);
main()
{
int num;
char pound , exp = ' ';
cout<<"Input the value of the width of the diamond\n";
cout<<"and the character you want displayed "<<endl;
cin>>num>> pound;
shape1(num, pound, exp);
shape2(num, pound, exp);
return 0;
}
void shape1(int n, char p, char e)
{
int c, j, t, l = 1;
for (c = n; c > 0; c--)
{
for ( j = 1; j <= n - 1; j++)
{
cout<<e;
}
for ( t = n - l; t < n ; t++)
{
cout<<p;
}
l += 2;
n--;
cout<<endl;
}
}
void shape2(int n, char p, char e)
{
int c, j, l = 1, k = 1, q = 1;
for ( c = n; c > 0; c--)
{
for ( j = n - l; j < n ; j++)
{
cout<<e;
}
for( q = 2*(c - 1) - 1; q > 0; q--)
{
cout<<p;
}
l++;
cout<<endl;
}
}
-
Re: How do I make a Diamond?
for (years = 0; years < 100000000, years ++)
{
compress_carbon();
}
Sorry, Sometimes I have to do this =)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks