Three combined functions in C++

  absolute-value, c++, function, iostream, std

I’m at the beginning of learning c++ and I’m understanding functions. I have a problem with an exercise. I have to use 3 functions, the first for input, the second for calculating the absolute value of the input number and the third to communicate it. Here’s what i tried.

#include <iostream>
#include <stdlib.h>
using namespace std;
float inp(float x)
{
    cin>>x;
    return x;
}
float vabs(float x)
{
    if(x<0)
        x=-x;  
    return x;
}
void cvabs(float x)
{
    cout<<vabs(x)<<endl;
}
int main()
{
    float a;
    inp(a);
    cvabs(a);
    system("pause");
}

For every number I insert, the program returns 0. Please, can you help me? Thanks in advance.

Source: Windows Questions C++

LEAVE A COMMENT