Drawing a sideways triangle or big X

Write a C++ program that consists of the main function and three user-defined functions.
The program prompts the user to choose from a menu whether to display a ‘sideway triangle’, or display a 'big X',
or to quit the program. After user’s selection, the program prompts the user to input:
1. A character to be used to draw the selected shape, and
2. The height (in lines on the screen) of the shape to draw. The height must be an odd positive number and your
program must check the user input for validity and not proceed until the height is entered correctly.

Can anyone tell me where I went wrong? It is not displaying correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

#include <iostream>
using namespace std;

int getUserInputSelection();
void drawSidewayTriangle(char character, int size);
void drawBigX(char character, int size);

int main() {

	int selection = 0;
	char character = 0;
	int size = 0;

	do {
		cout << "Welcome to the drawing program.\n";
		selection = getUserInputSelection();

		if (selection == 1) {
			cout << "\nPlease input a character for your brush: ";
			cin >> character;
			cout << "\nPlease enter the height of your triangle (odd positive number): ";
			cin >> size;
			while (size <= 0 || size % 2 == 0) {
				cout << "\nThe number you entered is not odd positive. Please try again.";
				cout << "\n\nPlease enter the height of your triangle (odd positive number): ";
				cin >> size;
			}
			drawSidewayTriangle(character,size);
			cout << "\n";
		}

		else if (selection == 2) {
			cout << "\nPlease input a character for your brush: ";
			cin >> character;
			cout << "\nPlease enter the height of your big X (odd positive number): ";
			cin >> size;
			cout << "\n";
			while (size <= 0 || size % 2 == 0)
			{
				cout << "\nThe number you entered is not odd positive. Please try again.";
				cout << "\n\nPlease enter the height of your triangle (odd positive number): ";
				cin >> size;
			}
			drawBigX(character,size);
			cout << "\n";
		}

		else if (selection == 3) {
			cout << "\nGoodbye!\n";
		}

		else {
			cout << "Invalid selection\n";
			selection = getUserInputSelection();
		}

		cout << "\n";

	} while (selection != 3);

	return 0;
}

int getUserInputSelection() {
	int selection;
	cout << "\nPlease select from the following menu:";
	cout << "\n   1. Draw a sideway triangle";
	cout << "\n   2. Draw a big X";
	cout << "\n   3. Exit the program";
	cout << "\n\nPlease input your selection: ";
	cin >> selection;
		
	return selection;
}

void drawSidewayTriangle(char character, int size) {
	for (int row = 0; row <= size; row++)
		for (int col = 0; col <= row; col++)
			cout << character;
}

void drawBigX(char character, int size) {
	for (int row = 1; row <= size; row++)
		for (int col = 1; col <= size; col++) {
			if ((row == col) || col == (size + 1)-row)
				cout << character;
			else
				cout << " ";
		}
	cout << endl;
}
In sideways triangle, you need to put some curly brackets and a cout<<endl;
1
2
3
4
5
6
7
8
void drawSidewayTriangle(char character, int size) {
	for (int row = 0; row <= size; row++)
            {  
		for (int col = 0; col <= row; col++)
			cout << character;
                cout<<endl;
            }
}

Similar thing in BigX. Put curly brackets after line 84 till the end of line 91. Otherwise you are executing only one command (line 91 should be executed after each row)
Yep that was it. Thanks appreciate it!
Topic archived. No new replies allowed.