Can't get my menu working

Hey I'm just doing my assignment for my intro to C++ class and decided to go for the extra credit question and tried to do a menu to run our programs.
Though I can't seem to get my menu to 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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
  #include <iostream>
#include <cmath>
#include <string>
#include <stdlib.h>

using namespace std;
void showWelcome();
void showMenu();
int task1();
int task2();
int task3();
int task4();
int task5();

int main()
{
int choice;     //menu choice
    
    
    //constants for menu choices
    const int Task_1 = 1,
              Task_2 = 2,
              Task_3 = 3,
              Task_4 = 4,
              Task_5 = 5,
              Quit   = 6;
    
    do
    {
         showWelcome(); // Show Welcome screen
         showMenu(); // Display Menu
         cin >> choice;
         
         //Validate menu selection
         while (choice < Task_1 || choice > Quit)
         {
               cout << "Please enter a valid menu choice: ";
               cin >> choice;
         }
         
         //If user does not want to quit, proceed.
         if (choice != Quit)
         {
                    switch (choice)
                    {
                           case Task_1:
                                int task1();
                                break;
                           
                           case Task_2:
                                int task2();
                                break;
                                
                           case Task_3:
                                int task3();
                                break;
                           
                           case Task_4:
                                int task4();
                                break;
                           case Task_5:
                                int task5();
                                break;
                    }
         }
        }while (choice != Quit);
         return 0;
}
//Welcome Function
void showWelcome()
{
     cout << "Welcome to Ibrahims Assignment" << endl << endl;
     system ("pause");
}

//Menu Function

void showMenu()
{    
    cout << "Please choose a task that you would like to run" << endl << endl
         << "1. Task 1 Miles per Gallon Calculator" << endl
         << "2. Task 2 Grade program" << endl
         << "3. Task 3 Ascending and Descending numbers" << endl
         << "4. Task 4 Temperature Converture Program"<< endl 
         << "5. Task 5 Coca Cola Machine" << endl
         << "6. Quit" << endl << endl;
}
//Task 1.
int task1()
{
double liters;
double miles;
double gallons;
double milespergallon;

cout << "Please enter number of liters of gasoline consumed\n";
cin >> liters;

//Converter for gallons per mile.
gallons = liters * 0.264179;

//Input for miles travelled.
cout << "Please enter the number of miles traveled by the car\n";
cin >> miles;

//Converter for gallons per mile.
milespergallon = miles / gallons;

//Output a table with litres, miles and gallons per mile.
cout << "\n\n\tLiters used\t"
<< "\tMiles travelled\t"<< "\tMiles per gallon\t"<< "\n"
<< "\t--------------------------------------------------------------------------\t"
<< "\n\n\t" << liters << "\t\t\t"<< miles << "\t\t\t" << milespergallon << "\n\n\n\\n\n";
}
//
//
//
//
//
//
//
//
//Task 2
int task2()
{
int score;
cout << "Please enter your mark\n";
cin >> score;

if (score < 59)
{
 cout << "You have failed, you got an F:";
}

else if (score >= 60 && score < 70)
{

 cout << "You need to try harder next time, you got a D:";

}

else if (score >= 70 && score < 80)
{

 cout << "Good effort, you got a C. See if you can do better next time!:";

}

else if (score >= 80 && score < 90)
{

 cout << "Great work! You got an B!:";

}

else if (score >= 90 && score < 100)
{
 cout << "Wow! You were one of the top performers, you scored an A!:";
}

else if(score == 100)
{

cout << "Perfect score! A+:";
}
}
//
//
//
//
//
//
//
//Task 3.
int task3()
{
double a;
double b;
double c;

cout << "Please enter your 3 numbers!\n\n";
cin >> a >> b >> c;

if (a < b && b < c)
{
cout << "The numbers in ascending order are\n" << a << "\n" << b << "\n" << c << endl;
cout << "The numbers in descending order are\n" << c << "\n"<< b << "\n" << a << endl;
}

else if (a < c && c < b)
{
cout << "The numbers in ascending order are \n" << a << "\n" << c <<"\n" << b << endl;
cout << "The numbers in descending order are \n" << b << "\n" << c <<"\n" << a << endl;
}

else if (b < a && a < c)
{
cout << "The numbers in ascending order are \n" << b << "\n" << a << "\n" << c << endl;
cout << "The numbers in descending order are \n" << c << "\n" << a <<"\n" << b << endl;
}

else if (b < c && c < a)
{
cout << "The numbers in ascending order are\n" << b << "\n" << c << "\n" << a << endl;
cout << "The numbers in descending order are\n" << a << "\n" << c << "\n" << b << endl;
}

else if (c < a && c < b )
{

cout << "The numbers in ascending order are\n" << c << "\n" << a << "\n" << b << endl;
cout << "The numbers in descending order are\n" << b << "\n" << a <<"\n" << c << endl;

}

else
{
cout << "The numbers in ascending order are " << c << "\n" << b << "\n" << a << endl;
cout << "The numbers in descending order are " << a << "\n" << b << "\n" << c << endl;
}
}
//
//
//
//
//
//
//Task 4
int task4()
{
  //Declaring all of my variables
  int lowlimit;
  int higherlimit;
  int step;
  //Program keeps warning me about this but I havto have it in their for my counter. Ask Ivan about it I guess.
  bool conditions = false;

  //Making sure the user inputs the correct numbers otherwise the program won't let them go on.
  while(!conditions)
  {
    cout << "Please enter a starting temperature (>0): ";
    cin >> lowlimit;
    cout << "Please enter an ending temperature (<5000): ";
    cin >> higherlimit;
    cout << "Please pick a step size (cannot be greater than diff in temperatures): ";
    cin >> step;
    //if user types everything correctly the program will continue.
    if(lowlimit > 0 && higherlimit < 5000 && step < (higherlimit - lowlimit))
    {
      conditions = true;
    }
    else
    {
      cout << "Something went wrong, please enter valid inputs";
    }
  }

  //This calulates how many intervals between the two limits.
  int steps = higherlimit / step;

  //This makes sure the program doesn't go over ending temp. (The % sign is the division remainder).
  if(higherlimit % step == 0)
  {
    steps--;
  }

 //Create an array for the farenheight temperatures to be inserted into (or pulled out of? still don't quite get it)
  int farenheight[steps];

  cout << "Celsius\t\t\tFarenheight" << endl;
  cout << "--------\t\t---------" << endl;

  //Run calculations and print table.

  for(int i=0;i<higherlimit/step;i++)
  {
    farenheight[i] = ((lowlimit + (i * step))* 9 / 5) + 32;
    cout << (lowlimit + (i * step)) <<"\t\t\t" << farenheight[i] << endl;
  }
}
//
//
//
//
//
//
//
//Declare a drink which is an int between 1 to 5.
int task5()
{
float userSelection;
float payment;
float change;
float drinkAmount;

cout << "Please insert your payment:";
cin >> payment;

if(payment<1.60)
{
    cout << "That is not enough money, please insert correct amount:";
    exit(EXIT_FAILURE);
}
cout << "Please select which drink you would like:\n 1.Coke:$1.60\n 2.Sprite:$1.60\n 3.Fanta:$.1.60\n 4.Lemonade:$2.50\n 5.Water:$2.00\n";
cin >> userSelection;

    if (userSelection == 1)
    {
        drinkAmount = 1.60;
        change = payment - drinkAmount;
        cout << "Your change is:$ " << change << endl << "Thank you!";
    }
    
    if (userSelection == 2)
    {
        drinkAmount = 1.60;
        change = payment - drinkAmount;
        cout << "Your change is:$ " << change << endl << "Thank you!";
    }
    if (userSelection == 3)
    {
        drinkAmount = 1.60;
        change = payment - drinkAmount;
        cout << "Your change is:$ " << change << endl << "Thank you!";
    } 
    if (userSelection == 4)
    {
        if(payment<2.50)
        {
            cout<<"You have not inserted enough money, please put correct amount in and try again";
        }
        
        drinkAmount = 2.50;
        change = payment - drinkAmount;
        cout << "Your change is:$ " << change << endl << "Thank you!";
    }
    if (userSelection == 5)
    {
        if(payment<2.00)
        {
            cout<<"You have not inserted enough money, please put correct amount in and try again";
        }
        drinkAmount = 2.0;
        change = payment - drinkAmount;
        cout << "Your change is:$ " << change << endl << "Thank you!";
    }
}
Please keep in mind we can't read minds, technology is not there yet. So please describe your problem in specifics. What exactly is not working?

Thumbs up on the code tags though.
int farenheight[steps];

You can't create an array like this. The size of the array must be a constant like int fahrenheit[10] or you need to create a dynamic array.
http://www.cplusplus.com/doc/tutorial/dynamic/
46
47
48
    case Task_1:
        int task1();
        break;

Here int task1(); is simply a declaration - it tells the compiler that the function exists. To actually call the function, just put task1(); without the int. Or assign the result to a variable, n = task1(); where n is some previously defined integer variable.
Topic archived. No new replies allowed.