I need help with an exercise that was given to me ages ago.. I just remembered it and realized that i never really got the answer..
This exercise is making a Christmas tree..
______* //the underlines are blank space
_____***
____***** <--(this i can do)
___*******
__*********
like so.. but instead of that i need spaces between * (stars)..
like this:
______*
_____*_*
____*_*_*
___*_*_*_*
i know how to do the math but can't really put it in the codes.. I'm stuck.
#include <iostream>
usingnamespace std;
int main() {
int height, stars = 1;
cout << "This program will create a christmass tree." << endl;
cout << "Just enter the height you want the tree to be." << endl;
cout << endl << "Enter the height of the tree: ";
cin >> height;
cout << endl << endl;
for(int i = 0; i < height; height--) {
for(int p = 0; p < height; p++)
cout << " ";
for(int y = 0; y < stars; y++)// should i have a for-loop
cout << "*"; // inside this for-loop?
stars += 2;
cout << endl;
}
system("pause>0");
return 0;
}