Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- int drawDiamond(int, char);
- using std::cout;
- using std::cin;
- using std::endl;
- using std::setw;
- int main() {
- int size;
- char character;
- back_size:
- cout << "Input the size of the canvas <uint>: ";
- cin >> size;
- if (static_cast<int>(size) < 3) {
- cout << "Enter a number equal to / larger than 3!\n\n";
- goto back_size;
- }
- cout << "Input the character you want to be used <char>: ";
- cin >> character;
- cout << endl;
- return drawDiamond(size, character);
- }
- int drawDiamond(int size, char character) {
- int i, j, wsize = (size - (size % 2)) / (size / 2);
- int half = size / 2;
- cout << setw(wsize);
- // First half
- for (i = 1; i <= half + 1; i++) {
- for (j = 1; j <= half + 1 - i; j++) {
- cout << setw(wsize) << character;
- }
- for (j = 1; j <= 2 * i - 1; j++) {
- if (j == 1 || j == 2 * i - 1)
- cout << setw(wsize) << character;
- else
- cout << setw(wsize) << ' ';
- }
- for (j = 1; j <= half + 1 - i; j++) {
- cout << setw(wsize) << character;
- }
- cout << endl;
- }
- // Second half
- for (i = half; i >= 1; i--) {
- for (j = 1; j <= half + 1 - i; j++) {
- cout << setw(wsize) << character;
- }
- for (j = 1; j <= 2 * i - 1; j++) {
- if (j == 1 || j == 2 * i - 1)
- cout << setw(wsize) << character;
- else
- cout << setw(wsize) << ' ';
- }
- for (j = 1; j <= half + 1 - i; j++) {
- cout << setw(wsize) << character;
- }
- cout << endl;
- }
- return 0; // Return a uint to the OS
- }
- // Exunys <3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement