error C2059: syntax error : 'return'

Hey guys, I'm relatively new to c++ , and I'm having trouble with my program I'm writing. It's supposed to ask user input for squares and rectangles, but it's not compiling right. Any kind of help or hints would be very much appreciated. Thanks in advance.

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <iostream>
using namespace std;


void DisplayMenu()
{
    cout << "Main Menu" << endl << endl;
    cout << "1. Draw a square" << endl;
    cout << "2. Draw a rectangle" << endl;
    cout << "3. Quit the program" << endl;

}


int GetUserMenuChoice()
{
    int menuChoice = 0;

    do
    {
        DisplayMenu();
        cin >> menuChoice;

        if (menuChoice < 1 || menuChoice > 3)
        {
            cout << "Please enter a valid menu choice: ";
            cin >> menuChoice;
        }

        else
        {
            cout << "You entered: " << menuChoice << endl << endl;

        }
    }
    return;
}




int GetSize()
{
    int size = 0;

    do
    {
        cout << "Enter a size value from 1-10: ";
        cin >> size;

        if (size < 1 || size > 10)
        {
            cout << "Please enter a valid size value: ";
            cin >> size;
        }

        else
        {
            cout << "You entered: " << size << endl << endl;
        }
    }

    return;
}


int GetHeight()
{
    int height = 0;

    do
    {
        cout << "Enter a height value from 1-10: ";
        cin >> height;

        if (height < 1 || height > 10)
        {
            cout << "Please enter a valid height value: ";
            cin >> height;
        }

        else
        {
            cout << "You entered: " << height << endl << endl;
        }
    }

    return;
}

int GetWidth()
{
    int width = 0;

    do
    {

        cout << "Enter a width value from 1-10: ";
        cin >> width;

        if (width < 1 || width > 10)
        {
            cout << "Please enter a valid width value: ";
            cin >> width;
        }

        else
        {
            cout << "You entered: " << width << endl << endl;
        }

    }

    return;
}


void DisplaySquare(int size)
{
    {
        int row = 0;
        int col = 0;

        for (col = 1; col <= size; col++)
        {
            cout << endl << endl;

            for (row = 1; row <= size; row++)
            {
                cout << " * ";
            }
        }
        system("pause");


    }

}

void DisplayRectangle(int height, int width)
{
    {
        int row = 0;
        int col = 0;

        for (col = 1; col <= height; col++)
        {
            cout << endl << endl;

            for (row = 1; row <= width; row++)
            {
                cout << " * ";
            }
        }
        system("pause");

    }

}



int main()
{
    int menuChoice = 0, size = 0, height = 0, width = 0;


    while (menuChoice != 3)
    {
        menuChoice = GetUserMenuChoice();

        switch (menuChoice)
        {
        case 1:		// Draw a square
            size = GetSize();
            DisplaySquare(size);
            break;
        case 2:		// Draw a rectangle
            height = GetHeight();
            width = GetWidth();
            DisplayRectangle(height, width);
            break;
        case 3:		// Quit the program
            cout << "Quitting program!" << endl;
            break;
        }
    }

    return 0;
}


The errors I am getting are:
error C2059: syntax error : 'return'
error C2059: syntax error : 'return'
error C2059: syntax error : 'return'

I'm not sure if I formatted the code right since it's my first time posting here, I will fix it if it didn't.
You never return anything in any of your functions. For example -

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
int GetUserMenuChoice()
{
    int menuChoice = 0;

    do
    {
        DisplayMenu();
        cin >> menuChoice;

        if (menuChoice < 1 || menuChoice > 3)
        {
            cout << "Please enter a valid menu choice: ";
            cin >> menuChoice;
        }

        else
        {
            cout << "You entered: " << menuChoice << endl << endl;

        }
    }
    return;
}


You want to return the menu choice right? Ofc you do! You then have to return it like this -

return menuChoice;

Then in main -

1
2
3
menuChoice = GetUserMenuChoice();

switch (menuChoice)


If say, the user chooses menu option 2. menuChoice will be equal to 2. Which works fine :)
Oops, I forgot to type those in. I was in the middle of trying to figure it out.

I did however get the program to work. Just needed to get rid of the do {}, it was unnecessary.
Thanks for the help!
Glad it worked out :)
Topic archived. No new replies allowed.