saving . . . saved functions in C & CPP has been deleted. functions in C & CPP has been hidden .
functions in C & CPP
Title
Question
#include<iostream>
using namespace std;
double add(double a, double b)
{
    double c = a + b;
}

int main()
{
    double sum;
    sum = add(50.4,4.5);
    cout<<"sum is : "<<sum<<"\\n";
    return 0;    
}

Output is
sum is : nan

May i know why the ans is nan for double data type?  Same has already worked for int. Is there any problem with double or float data type.


C-and-Cpp Functions 06-07 min 20-30 sec 29-02-20, 12:27 p.m. paresh.rkcet@gmail.com

Answers:

Please modify the function as below
double add(double a, double b)
{
double c = a + b;
return c;
}
The return type of your function is double so you are expected to return the value

29-02-20, 12:50 p.m. renethajb


Since double add(double a, double b); is a non-void function, you may need to return a double type at the end of the function. 
29-02-20, 2:39 p.m. ThiriTheWutYee


Log-in to answer to this question.