Star pyramid program

closed account (ECohb7Xj)
hi. I have written a star pyramid program, it adds two stars at a time but I want to rewrite the program so the stars double each time. Can you help me?



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
using namespace std;

int main()
{
	int a = 0, b = 8;

	for (int c = 1; c < 10; c++)
	{
		for (int space = b; space > 0; space--)
		{cout<<" ";}

		for (int i = 1; i < a; i++)
		{cout<<"*";}

		cout<<endl;

		a += 2;
		b--;
	}
	return 0;
}
Last edited on
I haven't tried any code but the way I would most likely approach it would to just multiply the count through each loop and multiply it by itself. You have a += 2;. Try to modify your code like a+= x*x; (ie. 6*6=36 or 6+6=12) Don't take that exact code seriously because that is most likely not the way to write it lol. That was just the first thing that popped into my head, just give it some thought. I would try to make a code for you but I am not in a suitable coding environment right now. That is my suggestion, hopefully someone else helps you with a much easier method
Last edited on
Topic archived. No new replies allowed.