First of all, hi everyone!
Im a C++ newbie and i'd like to get a good grasp of the concepts soon.
I'm currently working on this
#include <iostream>
using namespace std;
int main()
{
int i, j, lines;
cout << "This Program creates Christmas Trees." << endl;
do
{
cout << "Please enter a number between 1 and 30" << endl;
cin >> lines;
}
while (lines < 1 || lines > 30);
for(j = 1; j <= lines*2; j=j+2)
{
for(i=j; i <= 80 ; i=i+2)
{
cout << " ";
}
for(i = 1; i <= j; i++)
{
cout << "*";
}
cout << endl;
}
system ("pause");
return 0;
}
I understand everything except for the most important parts-- the for loops.
My textbook does a really poor job explaining them, and i am confused as what the int i, j mean
and how the loops work together.
This code asks the user to input a number between 1 and 30 and it creates a perfect triangle of asterisks (or a "Tree").
My problem is that like I said, I don't understand how the tree is done, or why you need the equations in the loops.
I'd greatly appreciate if someone could help me better understand these concepts!
Thanks a lot =]