Beginner

Starrk
2011-12-14
2012-09-26
  • Starrk
    Starrk
    2011-12-14

    I just can't get this to work

    include<iostream>

    define pi 3.14f

    using namespace std;
    int squareArea(int &);
    int circleArea(int &);

    int main()
    {
    int a = 10;
    cout<<squareArea(a)<<" ";
    cout<<circleArea(a)<<" ";
    cout<<a<<endl;
    return 0;
    }
    int squareArea(int &a)
    {
    return a = a;
    }
    int circleArea(int &r)
    {
    return r = pi
    r*r;
    }

    Errors are:
    In function int circleArea(int&)': converting toint' from `float'

    I kinda understand the second one but not sure what the first one is all
    about.

     
  • Josh Villegas
    Josh Villegas
    2011-12-19

    It's because pi is defined as a float and everything else is an int, so it has
    to convert the answer to an int when using pi in the circleArea function.

     
  • ilovepie10
    ilovepie10
    2011-12-24

    Define pi as a float