-
Division in C++
In C++ how may I divide and get a floating point result (ie 7/4 = 1.75). Wound you have to do this, or rather is this the only way?
int a, b;
float answer, answer2;
a=7;
b=4;
answer = a/b;
answer2 = a%b;
answer += answer2;
Is this the only way to do it? Is this the best way if I must compare two division results and I have to be able to compare all of the decimal places also. Thanks!
-
Re: Division in C++
you can cast the int's before division, i.e. use...
int a,b;
float answer;
answer = (float)a / (float)b;
-
Re: Division in C++
...or use something like that:
Code:
int a, b;
float answer=(float)a*exp(-log(b));