I'm supposed to print off stars. I prompt the user for a number (we'll call it n), and then print out n lines of stars. The first line will have one star and then it adds one each line.
eg.
Enter the number of lines -> 5
*
**
***
****
*****
I have this:
Code:#include <iostream> using namespace std; int main() { int n; cout << "Enter the number of lines." << endl; while (cin >> n) { //--- Loop counting i up from 1 to n. int i = 1; // Initialize counter. while (i <= n) { // Test counter. cout << "*"; i++; // Increment counter. } cout << endl; } return 0; }
That gives me the entered number of stars but I don't know how to get the lines of stars up to that point.
eg. If I run it now:
Enter number of lines -> 5
*****


Reply With Quote

Bookmarks