I have to write a code that prints out three figures and I got the first one down but have no idea how to even approach the other two. Below are the two I have to print out when a user inputs an odd number
#include <iostream>
usingnamespace std;
int main() {
int odd_Num;
bool mistake;
for (int i = 0; i < 3; i++) {
mistake = false;
cout << "Please enter a positive odd number < 40 for the size of the figures: " << endl;
cin >> odd_Num;
if (odd_Num > 40) {
cout << "Sorry your number is too big " << endl;
mistake = true;
}
if (odd_Num % 2 == 0) {
cout << "Sorry you entered an even number" << endl;
mistake = true;
}
if (odd_Num < 0) {
cout << "Sorry your number is not postive " << endl;
mistake = true;
}
if (!mistake) {
cout << "Thank You" << endl;
break;
}
elseif (i == 2) {
cout << "try again later" << endl;
exit(0);
}
}
for (int r = 0; r < odd_Num; ++r)
cout << "--";
cout << endl;
for (int r = 0; r < odd_Num; ++r) {
for (int c = 0; c < odd_Num; ++c)
if (c == odd_Num - 1)
cout << "*|";
else
cout << "* ";
cout << endl;
}
for (int c = 0; c < odd_Num; ++c)
cout << "--";
cout << endl;
}
/*
For the figure 3 you have to compute where you have to set a * depending on your r and c
in relation to odd_number.
odd_Number/2 returns the rounded down half of odd_Number so you have
under mid, mid and over mid
Example: odd_Number = 11
under mid =< 5
mid = 6
over mid > 6
*/
//under mid
if(r <= odd_Num/2)
/*
For under mid you have to get smaller with higher row count.
Column (c) must be equal or higher than row (r) AND
column must be lower than the total number of rows (odd_number) - row + 2
(+1 bacause c andr starts at 1 and +1 bacause c has to be lower).
Example: odd_Number = 11, r = 4
c >= r, true for c = 4 to 11
(11 - 4 +2) > c, true for c = 1 to 8
c = 4 to 11 AND 1 to 8 = 4 to 8
*/
if(c >= r && (odd_Num - r + 2) > c)
cout << "*";
else
cout << " ";
//over mid
elseif ((r - 1) > odd_Num/2)
/*
For over mid you have to get wider with higher row count.
Column (c) must be equal or lower than row (r) AND
column must be greater than the total number of rows (odd_number) - row.
Example: odd_Number = 11, r = 7
c <= 7, true for c = 1 to 7
(11 - 7) < c, true for c = 5 to 11
c = 1 to 7 AND 5 to 11 = 5 to 7
*/
if(c <= r && (odd_Num - r) < c)
cout << "*";
else
cout << " ";