Hey, yeah basically trying to write these two functions.
For the int integer part, I'm trying to separate the whole from the decimal.
Which i did this...
int integer(double number)
{
cin >> number;
int number2;
number2 = number2 - number;
return number;
}
------
int integer(double number)
{
double result;
return number;
}
Though, it's giving me
warning C4244: '=': conversion from 'double' to 'int', possible loss of data
warning C4244: 'return': conversion from 'double' to 'int', possible loss of data
error C2084: function 'int integer(double)' already has a body
Though I feel my function is doing the opposite....it's getting the decimal part. I think.
int integer( double number )
{
cin >> number; // this overwrites the value of number
// this function should compute something from its parameter
// no I/O
int number2; // uninitialized. Unknown value
number2 = number2 - number; // unknown - something is unknown
return number; // you did compute something into number2, but return number
}
The second is better:
1 2 3 4 5
int integer( double number )
{
double result; // unused variable
return number; // only a warning about conversion
}
The warning is about cases when the double has a value that is larger than what the int can store.
You should comment that your function will fail with such input.
The compiler does warn about the conversion, because it does not know whether you wrote it intentionally or by accident. Explicit conversion creates no warning: static_cast<int>(number)