Division & The Future of my C++

1.) I know this sounds dumb but my division formula won't work properly, and it multiplies instead. I (sadly) cannot find the problem.

Here's the whole thing:
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;

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

float 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();
}


2.) The second thing is: what am I going to do once I finish learning the basics of C++ (and actually advanced things too)? You can do great things with the command prompt (if that's not what it's called, I'm talking about the black window that the programs run on), but that's pretty limited, and its UI is terrible. Would I be able to make a program with at least a semi-decent UI (meaning you can at least click on things), make an OS, or something else? Basically, what could I do with C++ in the future??
1) The functions are fine. Just use the other function calls on line 33 and 40.

In order to properly use these functions, read below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
float diam (int a)
{
    float r;
    r=a/3.141592654;
    return (r); // notice how it returns a value?
} // this means that most of the time you'll use the assignment operator with this function

...
somevariable = diam (a); // assign the return value of diam (a) to somevariable
cout << somevariable; // output the value of somevariable to the screen
...
// compared to
...
cout << diam (a); // assign the return value of diam (a) to what?
...
// you could also do stuff like this:
...
if (diam (a) > 5) // lets say diam (a) returns 8.  the test expression really looks like this to the compiler:
    cout << "Value is greater than 5!\n";   // if (8 > 5)
...
Last edited on
Oh wow, I switched up the calling of my functions, so to find the circumference, I was calling the function that multiplied by pi, and it was switched around with the diameter function too.

@ Phil123 and soranz: I do understand what you guys were saying though, thanks.

~Solved~
Topic archived. No new replies allowed.