Hello, I am learning about printing shapes using nested for loops in c++. I'm comfortable printing triangles and rectangles but I have come across and assignment that I can't figure out.
I have to write a program that prints an oval using the character '*'. The user will enter the number of '*'s on the middle row and then the number of rows above and below the middle row. No row is allowed to have less than two '*'s and the code will check for this. For instance, an oval with 16 '*'s in the middle row and 2 rows above and below looks like:
************
**************
****************
**************
************
(In case the formatting did not work the first line should begin with 2 spaces, the second with 1 space, the fourth with 1 space and the fifth with 2 spaces)
I have my variables declared and my program reads in the mid row length and the number of rows above and below and checks that they fit the guidelines. I have no idea where to start with printing the oval. Any help is appreciated!
#include <iostream>
#include <cmath>
usingnamespace std;
int main()
{
// Declare and initialize variables
int midRow(0);
int numRows(0);
// Repeatedly prompt for middle row size until valid value is entered
cout << "Enter size of the middle row: ";
cin >> midRow;
if (midRow < 3){
cout << "Size of the middle row must be at least three." << endl;
cout << "Enter size of the middle row again: ";
cin >> midRow;
}
// Repeatedly prompt for the number of rows until valid value is entered
cout << "Enter number of rows: ";
cin >> numRows;
if (midRow - (2 * numRows) < 2){
cout << "Invalid number of rows." << endl;
cout << "Enter number of rows again: ";
cin >> numRows;
}