-
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:
*
**
***
****
*****
-
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.
-
Re: Triangle using C++
Hey, it must have way that I will make this one triangle.
++++*
+++**
++***
+****
*****
'+' Should be blank fields!
-
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.
-
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.
Page generated in 1,717,390,571.49346 seconds with 10 queries