Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 04-02-2009
Member
 
Join Date: Oct 2008
Posts: 47
Triangle using C++

Is there anyone who can help me to make a triangle like this? (Must use if and else statements!)

*
**
***
****
*****

--------------------------------------------------
Can easily do the following:

Code:
# include <iostream> 

using namespace std; 

int main(){

int row, col; 

cout << "Enter col"; 
cin >> col; 

cout << "Enter row"; 
cin >> row; 

char a ='*'; 


for(int i=1;i<=col;i++){ 

for(int x<=5;x>i;x--){

cout <<a; 

}
cout <<endl; 
}

system ( "pause"); 
return 0; 
}

Quote:
*
**
***
****
*****
Reply With Quote
  #2  
Old 04-02-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Triangle using C++

Now it's so long since I've coded in c++, so the code I can not help you.

But it is surely something to put a boolian to false and then check whether it is false, and set it to true when the stars are obtained. And then do a "goto start" or the like. if you can.
Reply With Quote
  #3  
Old 04-02-2009
Member
 
Join Date: Oct 2008
Posts: 47
Re: Triangle using C++

Hey, it must have way that I will make this one triangle.

++++*
+++**
++***
+****
*****

'+' Should be blank fields!
Reply With Quote
  #4  
Old 04-02-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: Triangle using C++

Maybe something like:
Code:
# include <iostream> 
using namespace std; 
int main() 
{

int row,col; 

cout << "Enter col"; 
cin >> col; 

cout << "Enter row"; 
cin >> row; 

char a ='*'; 

for (int i = 1; i <= col, i ++) 
{
for (int x = 0, x <col - i; x ++) 
cout << ""; 

for (int x = 0, x <i, x ++) 
cout << a; 
cout << endl; 
}

system ( "pause"); 
return 0; 
}
What are "row" used for?

I am not sure that "int x<= 5" makes sense.
Reply With Quote
  #5  
Old 04-02-2009
Member
 
Join Date: Oct 2008
Posts: 47
Re: Triangle using C++

Thank you for your reply kelfro. It was just what I was looking for. You have the right terms for the "row" but had used it in another task.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Triangle using C++"
Thread Thread Starter Forum Replies Last Post
Triangle generator gelsys1208 Software Development 3 13-10-2010 04:32 AM
utorrent yellow triangle indicator Rily Windows Software 3 24-06-2010 03:44 PM
What is the Code for Floyd's triangle in C ?? Silent~Kid Software Development 5 02-01-2010 07:43 PM
Want To Print Triangle In C++ vishodhan Software Development 1 08-01-2009 09:53 PM
Yellow triangle in the taskbar harakim Windows Software 3 03-10-2008 03:09 PM


All times are GMT +5.5. The time now is 09:08 AM.