ignoring switch case?

For some reason it's ignoring the instruction under each case. The menu appears, I select an option and it just skips to "would you like to run the program again?" Why is it ignoring the cases? Someone please help!

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
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
#include <istream>
#include <math.h>

    //prototypes
    double Area_Circle(int);
	int Area_Rectangle(int,int);
	int Area_Square(int);
	int Menu();
	int Input_Side();
	int Input_Radius();
	void Output_Rectangle(int,int,double);
	void Output_Shape(int,double);
    
    
using namespace std;

int main()
 {  
	
	int radius, width, length, side, choice; //declare integer variables
	double area; //declare double variables
	char answer;
    do // do while loop to display the menu again
	{
    	choice = Menu(); //assign the value returned by Main function to choice variable
    	
    	switch(choice) 
    	{
    	case 1: width = Input_Side(); //assign the returned value to width
            length = Input_Side(); //assign the returned value to length
    		area = Area_Rectangle(width,length); //assign the returned value to area
    		cout << "Rectangle:\t" << "Width\t" << "Length\t" << "Area\n";
    		Output_Rectangle(width,length,area);
    		break;
    	case 2: 
            radius = Input_Radius();
    		area = Area_Circle(radius);
    		cout << "Circle:\t" << "Radius\t" << "Area\n";
    		Output_Shape(radius,area);
    		break;
    	case 3: 
            side = Input_Side();
    		area = Area_Square(side);
    		cout << "Square:\t" << "Sides\t" << "Area\n";
    		Output_Shape(side,area);
    	    break;
        case 4: 
            cout << " Have a nice day!" << endl << endl;
            break;
    	//default: cout << "Invalid choice. Try again. " << endl << endl;
        }    
        cout << "Would you like to run the program again? (Y or N) ";
        cin >> answer;
        cout << endl;
	}while(answer == 'Y' || answer == 'y');
	
			
	system("PAUSE");
    return EXIT_SUCCESS;

}

    int Menu()
    {
         int choice;
         cout << "\n Choose a shape to calculate AREA";
	     cout << "\n...................................";
         cout << "\n 1- Rectangle\n 2- Circle\n 3- Square\n 4- Exit";
	     cout << "\n\n Enter your choice: ";
	     cin >> choice;
    }
    int Input_Side()
    {
        int side;        
        cout << "\n Enter side: ";
		cin >> side;
		return (side);
    }
    int Input_Radius()
    {
        int radius;
        cout << "\n Enter the radius: ";
        cin >> radius;            
        return (radius);
    }
	double Area_Circle(int radius)
	{  
         return (3.14 * radius * radius);
	}
	int Area_Rectangle(int length,int width)
	{  
         return (length * width);
	}
	int Area_Square(int side)
	{  
         return (side * side);
	}
	void Output_Rectangle(int width, int length, double area)
    {
        cout << "\t\t" << width << "\t" << length << "\t" << area;
    } 
    void Output_Shape(int side, double area)
    {
        cout << "\t\t" << side << "\t" << area;
    }
closed account (zb0S216C)
You're not returning the user's choice from "::Menu( )". Normally, compilers are not allowed to assume a return value of function defined by the programmer except for "main( )". You have to return something.

Wazzak
Last edited on
You forgot to return choice from Menu().
omg what an idiot i am! :) thanks guys
Topic archived. No new replies allowed.