Could someone explain from where that value get ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Could someone explain from where that value get ?

i wrote for fun calculate on template too work with double and int. i wrote somthing like that code : #include <iostream> using namespace std; template <class Cal1> Cal1 sum(Cal1 a, Cal1 b) { return a+b; } template <class Cal1> Cal1 sub(Cal1 a, Cal1 b){ return a-b; } template <class Cal1> Cal1 mul(Cal1 a, Cal1 b){ return a*b; } template <class Cal1> Cal1 divi(Cal1 a, Cal1 b){ if (a != 0 && b != 0){ return a/b; } else { cout << "Error division by 0 "; } } int main() { double x=0.0 , y=2.0; cout << sum(x,y) << endl << sub(x,y) << endl; cout << mul(x,y) << endl; cout << divi(x,y); return 0; } its working but i get some additional output and i don't know how too kick that output: 2 -2 0 Error division by 0 1.#QNAN what is that 1.#QNAN ? thx for explains

22nd Apr 2017, 6:38 PM
MKey
MKey - avatar
5 Answers
+ 3
ok i find where it's it :) function return result of a/b. I just add return 0 line.
22nd Apr 2017, 6:42 PM
MKey
MKey - avatar
+ 3
right my mistake ;)
22nd Apr 2017, 6:50 PM
MKey
MKey - avatar
+ 3
i write wrong condition: if ( a!=0 && b!=0) now i edit it and its just if (b!=0)
22nd Apr 2017, 6:58 PM
MKey
MKey - avatar
+ 2
its not division by 0. you are doing 0.0/2.0, which is 0.0
22nd Apr 2017, 6:49 PM
Bebida Roja
Bebida Roja - avatar
+ 1
so from where did the division by zero output came from?
22nd Apr 2017, 6:51 PM
Bebida Roja
Bebida Roja - avatar