 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Sat Nov 18, 2006 10:10 am Post subject: Need help with Triangles program |
|
|
I have another program to write, i will appreciate if somebody can
help......prompts the user to enter positive integer, and then prints
out four triangles
For Example: If we enter 4 it should shows
*
* *
* * *
* * * *
* * * *
* * *
* *
*
* * * *
* * *
* *
*
*
* *
* * *
* * * *
I have also tried to create this program but i couldn't be able to
correct the formating of "*".
UW PICO(tm) 4.10
File: triangle.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Enter a character:>";
int n;
cin >> n;
for ( int row = 0; row < n; row++ )
{
for ( int column = 0; column <= row; column++ )
cout << ' ';
for ( int column = 0; column < (3 - row); column++ )
cout << " * ";
cout << " "<< endl;
cout << endl;
}
for ( int row = 0; row < n; row++ )
{
for ( int column = 0; column <= (3 - row); column++ )
cout << " * ";
cout << " ";
cout << endl;
}
cout<<endl;
for ( int row = 0; row < n; row++ )
{
for ( int column = 0; column <= row; column++ )
cout << " * ";
cout << " ";
cout << endl;
}
cout<<endl;
for ( int row = 0; row < n; row++ )
{
for ( int column = 0; column < row; column++ )
cout << ' ';
for ( int column = 0; column <= (3 - row);
column++ )
cout << " * ";
cout << endl;
}
return 0;
} // function main |
|
| Back to top |
|
 |
Alf P. Steinbach Guest
|
Posted: Sat Nov 18, 2006 10:10 am Post subject: Re: Need help with Triangles program |
|
|
* asif929 (AT) hotmail (DOT) com:
| Quote: | #include <iostream
using namespace std;
int main()
{
cout << "Enter a character:>";
int n;
cin >> n;
for ( int row = 0; row < n; row++ )
{
for ( int column = 0; column <= row; column++ )
cout << ' ';
for ( int column = 0; column < (3 - row); column++ )
cout << " * ";
cout << " "<< endl;
cout << endl;
}
|
Try correcting the indenting to see the real structure of this code.
To help with that, /always/ put {} braces around a loop body.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|