Hello, guys I'm hoping that you can help me. I'm having a problem coding w/ this problem. I find it hard to do this bcoz when I run the program the result always be like this.
#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;
int main()
{
for (int n = 10; n >= 0; n-=2)
{
if (n == 0) n = 1;
cout << string (n, '*') << endl;
}
system ("pause");
return 0;
}
result:
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
I don't know what to do. the problem is written below.
If someone could help me figure this kind of triangles (below) it will be great.
I will really aprreciate your effort guys. Ty
=====================================
Write a program that outputs a triangle made out of asterisks. The size of the triangle depends on the input of the user. For example, if the user inputs 3, the triangle will look like that of Triangle 1, if the input is 5, the triangle will look like Triangle 2, and if the input is 7, the triangle will look like Triangle 3. Hint: (1) Use one loop for asterisks and another loop for spaces or blanks (2) There are a total of three loops.
Answer the problem by providing three different program codes which use different loop statements:
- for loop
- while loop
- do…while loop
Triangle 1
*
* *
* * *
Triangle 2
*
* *
* * *
* * * *
* * * * *
Triangle 3
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *