Circumference Formula

Okay, I'm making another formula to calculate circumference...but now I'm messing with if/else statements (I forgot the proper term for that, sorry). Because of that, I decided to add a function where you can calculate diameter also.

So basically with this, you can calculate circumference or diameter based on which value you have.

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
#include <iostream>

using namespace std;

int circ (int b)
{
    float s;
    s=b*3.141592654;
    return (s);
}

int diam (int a)
{
    float r;
    r=a*3.141592654;
    return (r);
}

int main()
{
  int input;

  cout<<"1. Calculate circumfrence\n";
  cout<<"2. Calculate diameter\n";
  cout<<"3. Exit\n";
  cout<<"Selection: ";
  cin>> input;
  if ( input==1 )
  {
      int diam;
      cout << "Insert diameter: ";
      cin >> diam;
      cout << "Result: " << int diam (int a) << "\n";
  }
  else if (input==2)
  {
      int circ;
      cout << "Insert circumfrence: ";
      cin >> circ;
      cout << "Result: " << int circ (int b) << "\n";
  }
  else if (input==3)
  {
      cout<<"Goodbye.\n";
  }
  else
  {
      cout<<"Failed to press a relevant number, exiting...\n";
  }
  cin.get();
}


Errors

Line 33: Expected primary expression before 'int' AND Expected ';' before 'int'

Line 40: Same as above

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
#include <iostream>
int circ (int b)
{
    float s;
    s=b*3.141592654;
    return (s);
}

int diam (int a)
{
    float r;
    r=a*3.141592654;
    return (r);
}

int main()
{
  int input;

  cout<<"1. Calculate circumfrence\n";
  cout<<"2. Calculate diameter\n";
  cout<<"3. Exit\n";
  cout<<"Selection: ";
  cin>> input;
  if ( input==1 )
  {
      int a;
      cout << "Insert diameter: ";
      cin >> a;
      cout << "Result: " <<  diam(a) << "\n";
  }
  else if (input==2)
  {
      int b;
      cout << "Insert circumfrence: ";
      cin >> b;
      cout << "Result: " << circ(b) << "\n";
  }
  else if (input==3)
  {
      cout<<"Goodbye.\n";
  }
  else
  {
      cout<<"Failed to press a relevant number, exiting...\n";
  }
  cin.get();
}
your function calling worng .
int function_name(int a)
{
statements
}

calling fuction
function_name(arguments);
cout<<function_name(a);
Thanks a lot!
Topic archived. No new replies allowed.