calculate area of a circle not working (FIXED)

I'm writing a function to calculate the area of a circle and I can't seem to get it to work. Does anyone know what's wrong?


EDIT: NEVERMIND I got it, there was just a bunch of small errors.

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
#ifndef TEDIOUS_MATH_FUNCTIONS_H_INCLUDED
#define TEDIOUS_MATH_FUNCTIONS_H_INCLUDED

#include <iostream>
using namespace std;

const double pi = 3.1415926535897;

double areaofcircle() // make this work with more shapes later
{
    cout << "Will you be using the radius or the diameter? (type \"r\" for radius, and \"d\" for diameter)" << endl;
    char radiusordiameter;
    cin >> radiusordiameter;

    double area = 0;

    for(bool flag = false; flag != true;) //makes a loop to where you don't have to keep restarting program if you input the wrong thing
    {
        switch(radiusordiameter) //calculates area depending on if radius or diameter is used
        {

        double input = 0;

        case 'r': //calculates area using radius
            cout << "Input the radius" << endl;
            cin >> input;
            area = pi * input * input;
            return area;

        case 'd': // calculates area using diameter
            cout << "Input the diameter" << endl;
            cin >> input;
            area = pi/4 * input * input;
            return area;

        default: // wrong input
            cout << "You did not tell me if you are using diameter or radius, please try again" >> endl;
        }
    }
}

#endif // TEDIOUS_MATH_FUNCTIONS_H_INCLUDED
Last edited on
Since you never change the value of flag, you could replace line 17 with while(true)
Topic archived. No new replies allowed.