(LINUX - C++ - (using Dev C++) Write a C++ program that should have meaningful v
ID: 3627705 • Letter: #
Question
(LINUX - C++ - (using Dev C++)Write a C++ program that should have meaningful variable names, comments, and proper indentation.
program should declare the following variables:
a. number of lines
b. other variables as needed
Program will display a message asking the user "how many lines"
program will then input the number of lines. Positive numbers are allowed
program should loop as many times as "number of lines" and for each line through the loop it should generate as many asterisks as the 2(line number-1)+1. That is one asterisk on line 1, three asterisks on line 2, etc
The asterisks should form a pyramid
Example w/ three lines:
*
***
*****
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
int num_lines = -1;
while (num_lines < 0)
{
std::cout << "how many lines?" << endl;
std::cin >> num_lines ;
}
for( int x = 0; x < num_lines ; x++)
{
int c = 2 * (x -1) + 1;
for (int i = 1; i < c + 1; i++)
{
cout << "*";
}
cout << endl;
}
cin >> num_lines;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.