May 31, 2011 at 4:46pm UTC
OK, I am trying to write a simple prog to take a couple variables and pass them to four functions and return the results.
All I get is QNAN.
Here is that code. Please tell me what I'm doing wrong.
#include<iostream>
using namespace std;
//Declare functions
double multiplication();
double division();
double addition();
double subtraction();
//Define functions
double multiplication(double x, double y)
{
double z;
z = x * y;
}
double division(double x, double y)
{
double z;
z = x / y;
}
double addition(double x, double y)
{
double z;
z = x + y;
}
double subtraction(double x, double y)
{
double z;
z = x - y;
}
int main()
{
//Declare and initialize variables
double a, b, e, f, g, h;
a = 5;
b = 6;
//Function calls
e = multiplication(a, b);
cout << e << endl;
f = division(a, b);
cout << f << endl;
g = division(a, b);
cout << g << endl;
h = division(a, b);
cout << h << endl;
}
May 31, 2011 at 4:51pm UTC
Your functions are returning garbage, because you don't call return in them. I'm suprised it even compiled!
May 31, 2011 at 5:03pm UTC
NAN is an acronym for Not a Number . As Kooth said, your methods are returning unused pieces of memory, or garbage . So, when you assign e the returning value of multiplication( a, b ) for example, e is given garbage as well.
Do as Kooth suggested, and put return statements in your methods.
Wazzak