Commit 9bce2395 authored by Michael's avatar Michael

michael.davityan:exercise_05_24v10

parent 3f7a5c7d
Error 1: wrong number(must be odd number from 1->19). Error 1: wrong size value(must be odd number from 1->19).
Error 1: wrong number(must be odd number from 1->19). Error 1: wrong size value(must be odd number from 1->19).
Error 1: wrong number(must be odd number from 1->19). Error 1: wrong size value(must be odd number from 1->19).
...@@ -5,20 +5,20 @@ ...@@ -5,20 +5,20 @@
int int
main() main()
{ {
int lineCount; int rhombusSize;
if (::isatty(STDIN_FILENO)) { if (::isatty(STDIN_FILENO)) {
std::cout << "insert line count(must be odd number from 1->19): "; std::cout << "insert rhombus size(must be odd number from 1->19): ";
} }
std::cin >> lineCount; std::cin >> rhombusSize;
if (lineCount % 2 == 0 || lineCount < 1 || lineCount > 19) { if (rhombusSize % 2 == 0 || rhombusSize < 1 || rhombusSize > 19) {
std::cerr << "Error 1: wrong number(must be odd number from 1->19).\n"; std::cerr << "Error 1: wrong size value(must be odd number from 1->19).\n";
return 1; return 1;
} }
const int ROW_LIMIT = lineCount / 2; const int rowLimit = rhombusSize / 2;
for (int row = -ROW_LIMIT; row <= ROW_LIMIT; ++row) { for (int row = -rowLimit; row <= rowLimit; ++row) {
const int columnLimit = ROW_LIMIT - std::abs(row); const int starStart = rowLimit - std::abs(row);
for (int column = -ROW_LIMIT; column <= columnLimit; ++column) { for (int column = -rowLimit; column <= starStart; ++column) {
std::cout << (column < -columnLimit ? " " : "*"); std::cout << (column < -starStart ? " " : "*");
} }
std::cout << std::endl; std::cout << std::endl;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment