Very beginner string question

Hi, I am just starting to learn C++ and am working through Accelerated C++. I wrote the following code to practice creating strings. I keep getting error messages on the first two string constructions (in the two if statements). The last one (in the else statement) works fine. My question is, is it because the variables are type int and not type size_t? Or is the problem something else?

I know I could just use nested for loops, but I'd love to know why this method doesn't work.

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
int main()
{
	// ask user for desired shape
	cout << "Do you want to draw a SQUARE, a RECTANGLE, or a TRIANGLE?";

	// process user input of shape name
	string shape; // define shape
	cin >> shape; // read shape

	// draw square
	if (shape = "SQUARE")
	{
		cout << "How tall/wide should the square be?"; // ask user for value
		int base; // define base
		cin >> base; // read value

		// draw square
		for (int i = 0; i < (base - 1); ++i)
		{
			const string row(base,'*');
			cout << row << endl;
		}
	}
	if (shape = "RECTANGLE")
	{
		cout << "What is the base of the rectangle?";
		int base; // define base
		cin >> base; // read value
		cout << "What is the height of the rectangle?";
		int height; // define height
		cin >> height; // read value

		const string row(base, '*'); // build a string

		// draw rectangle
		for (int i = 0; i < (height - 1); ++i)
		{
			const string row(base, '*'); // build a string
			cout << row << endl; // display the string
		}
	}
	else
	{
		cout << "what is the base of the triangle?";
		int base; // define base
		cin >> base; // read value

		// draw triangle
		for (int i = 0; i < (base - 1); ++i)
		{
			const string row(i + 1, '*'); // build a string of *'s
			cout << row << endl;
		}
	}

	// hold window open
	char holdExecutionWindowOpen;
	std::cin >> holdExecutionWindowOpen;

	// return
	return 0;
}


Also, the compiler isn't returning any errors for my if statements. Are non-nested if {} if {} else {} viable?
Wait. I'm dumb. I changed the equals signs in the if statements to double equals signs, and that um, sorta fixed it.
Topic archived. No new replies allowed.