C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need help with Triangles program

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Nov 18, 2006 10:10 am    Post subject: Need help with Triangles program Reply with quote



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





PostPosted: Sat Nov 18, 2006 10:10 am    Post subject: Re: Need help with Triangles program Reply with quote



* 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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.