Menu Function Problem

Hi there, I am having problems with setting up a menu as a function. The point of the menu is to display a list of 4 options and the user is supposed to choose one option and then the program will run. I am having trouble understanding how to display the menu once I run it because it is not working. I can't figure out what is wrong with it. Please, help! 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <iostream>

using namespace std;

int menu(int ans);   // function declaration for menu
void draw_triangle(int size,  char ch);  //function declaration for triangle
void draw_downtri( int size,  char ch);  // function declaration for upside-down triangle
void draw_diamond(int size,  char ch);   //function declaration for diamond
void draw_side(int size,  char ch);      // function declaration for side ways triangle

int main()
{
    int size =1,ans;
    char ch;

     menu(int ans); //function call

    // starts switch

    switch (ans)
    {
        case 1: // Triangle

            cout<< "Please enter your desired size of the triangle \n";
            cin >> size;

            cout << "Please enter the type of character you'd like to use \n";
            cin >> ch;

                draw_triangle(size, ch);   //function call

              break;

        case 2: // Upside down triangle

            cout << "Please enter your desired size \n";
            cin >> size;

            cout << "Please enter the character \n";
            cin >> ch;

                draw_downtri(size, ch);   //function call for upside down triangle

         break;

        case 3: // Diamond

            cout << "Please enter your desired size \n";
            cin >> size;

            cout << "Please enter the character type you'd like to use \n";
            cin >> ch;
            cout << endl;

                draw_diamond(size,ch);   //function call for diamond

            break;

        case 4: // Side way triangle


            cout << "Please enter your desired size \n";
            cin >> size;

            cout << "Please enter the character \n";
            cin >> ch;
            cout << endl;

                draw_side(size,ch);     //function call for side ways triangle


               break;



    }

    return 0;
}

int menu(int ans)
{
    bool incorrectinput = true;


    cout << "Please select which drawing you would like to create (1-4) \n";

    while(incorrectinput)

    cout <<" 1. A regular triangle \n";
    cout <<" 2. An upside down triangle \n";
    cout <<" 3. A diamond \n";
    cout <<" 4. A side-way triangle \n";
    cin >> ans;

    if(ans==1 || ans==2 || ans==3 || ans==4)
    incorrectinput= true;

    else
            incorrectinput = false;
    cout <<" Sorry, please input a correct input! \n";
            
    return (ans);
}

void draw_triangle(int size, char ch)
{ int i,j;

        for ( i =1 ; i <= (size) ; i++)           //this displays the size.
        {

             for (j=0; j <(2*size -i); j++)       //this displays the spaces.
             {
                 cout << " ";
             }
             for (j=0; j < 2*i-1; j++)           //this displays the character chosen by the user.
             {
                   cout << ch;
             }
   }               cout <<endl;
}

void draw_downtri( int size, char ch)
{ int i,j;

    for ( i =size ; i >= 1 ; i--)           //this displays the size.
    {

         for (j=0; j <(2*size -i); j++)       //this displays the spaces.
         {
             cout << " ";
         }
         for (j=0; j < 2*i-1; j++)           //this displays the character chosen by the user.
         {
               cout << ch;
         }

         cout <<endl;
    }
}

void draw_diamond(int size,  char ch)
{ int i,j;

    for( i=0; i<size ; i++ )      //controls loop for rows
    {
        for (j=0; j < (2*size-i); j++)
        {
            cout << " ";
        }
        for (j=0; j < 2*i-1  ; j++)  // controls loop for columns
             {
                cout<< ch;
             }
        cout <<endl;

    }
    for ( i =size ; i >= 1 ; i--)           //this displays the size.
    {

         for (j=0; j <(2*size -i); j++)       //this displays the spaces.
         {
             cout << " ";
         }
         for (j=0; j < 2*i-1; j++)           //this displays the character chosen by the user.
         {
               cout << ch;
         }

         cout <<endl;
    }
}
void draw_side(int size, char ch)
{ int i,j;

    int columns=1;

    for ( i =0 ; i < size  ; i++)           //controls loop for rows
    {

         for (j=0; j < columns ; j++)       //this the columns
         {
             cout << ch;
         }

         cout <<endl;
         columns++;
    }

    for ( i = size ; i >=0 ; i--)
    {
        for (j= 0; j < columns ; j++)
        {
            cout << ch;
        }

        cout <<endl;
        columns--;
    }
    cout << columns;
}



menu(int ans); //function call
Nope, This is invalid and should cause an error.
switch (ans)
You didn't assign a value to ans anywhere. Make use of return value of your function.
Topic archived. No new replies allowed.