Calculator Program with Classes, Switch or If's ?

Hey guys im making a Calculator that returns Rectangles, Triangles or Circles Area. the thing is that i already set up everything but I need to do something to let the user coose between which Figure it needs to calc. How can would a class could be used for each figure?
HereĀ“s the code im sorry for the bothering im just a noob lol.


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
#include <iostream>
#include <cmath>
using namespace std;
int main (){
	int choice = 0;
	cout<< ("Please enter: ") << endl;
	cout<< ("1) To calculate a Rectangle's Area.") << endl;
	cout<< ("2) To calculate a Triangles's Area.") << endl;
	cout<< ("3) To calculate a Circle's Area.") << endl;
	cin>> choice;


	//Rectangle


		 double w, l, h, ArRect;

      cout << "Rectangle Area" << endl << ("Please enter the width, length and height.");
      cin >> w >> l >> h;
	  
	  ArRect = w * l * h;

	  cout << ("The Area of the Box is: ") << ArRect << endl;

system ("Pause");

return 0;

	
// Triangle


double l1, l2 ,l3, s, ArTri;
		   

	cout<< ("Please enter the values for the three  sides.") << endl;
		cin >> l1 >> l2 >> l3;
		s = ((l1 + l2 + l3)/2);
		ArTri = (sqrt(s*(s-l1) * (s -l2) *(s-l3)));

		cout << ("The Triangle's Area is: ") << ArTri << endl;

		system ("Pause");
}
	

//Circle
		double ACir, R;
		double Pi = 3.1416;

		cout<< ("Please Enter the value of the Radius of the Circle.") << endl;
		cin>> R;

		ACir = (Pi * (pow(R,2)));
		cout<< ("The Circle's Area is: ") << endl;

system ("Pause");

return 0;

}
after you read choice:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
switch(choice) {
  case 1:
    //Rectangle
    ...
    break;
  case 2:
    // Triangle
    ...
    break;
  case 3:
    //Circle
    ..
    break;
  default:
    std::cout << "wrong choice";
}
Thank you so much :) ill try it! have a nice day
Topic archived. No new replies allowed.