/* I am currently learning c++ as part of my core subjects */
Strangely, while writing another long program i ran into this instance
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int a,b,res; float c;
cin>>a;
cin>>b;
cin>>c;
res=(a-b)/c;
cout<<res;
}
Input :
a = 2 b = 1 c = 0.2
Output :
4
Desired Output :
5
I need to find res, (the number of steps of increment c) in between the starting a and end b truncated to the closest floor integer value.
I tried defining (a-b) as another int, still same result 4 instead of 5.
But simply testing
int main()
{
cout<<(2-1)/0.2;
}
correctly gave 5.
One more doubt: if I do not define any variable, like above, what datatype will the system assume for the result?