I know this topic exists but I'm not asking how to do it. I was reading and doing the examples from a book I'm reading. The code for it is pretty straight forward, but not sure if I'm missing something because I'm not getting the output I was expecting. Just wanting input on if I am missing something. You know how your mind fills in what should be there so I need fresh eyes on the code.
OS: Windows Vista Home Basic 32-bit
IDE/Compiler: Code::Blocks/MinG
Book says it should be:
*
* *
* * *
The program output is actually this:
*
**
***
// Example 7-1B
// Program: Prints a triangle of stars
#include <iostream>
usingnamespace std;
void printStars(int blanks, int starsInLine);
int main()
{
int noOfLines; // variable to store the number of lines
int counter; // for loop control variable
int noOfBlanks; // variable to store the number of blanks
cout << "Enter the number of star lines (1 to 20) to be printed: ";
cin >> noOfLines;
while (noOfLines < 0 || noOfLines > 20)
{
cout << "Number of star lines should be between 1 and 20" << endl;
cout << "Enter the number of star lines (1 to 20) to be printed:";
cin >> noOfLines;
}
cout << endl << endl;
noOfBlanks = 30;
for (counter = 1; counter <= noOfLines; counter++)
{
printStars(noOfBlanks, counter);
noOfBlanks--;
}
return 0;
}
void printStars(int blanks, int starsInLine)
{
int count;
for (count = 1; count <= blanks; count++)
cout << ' ';
for (count = 1; count <= starsInLine; count++)
cout << '*';
cout << endl;
}