I seriously dislike QNAN

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;
}
Your functions are returning garbage, because you don't call return in them. I'm suprised it even compiled!
You are quick.

Thanks!
closed account (zb0S216C)
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
Topic archived. No new replies allowed.