#include"iostream"
using namespace std;
int main(){
float arithmetic_operation = (4+5)+9*2-4+2/5+1-13;
cout<< arithmetic_operation << " <--The Result." << endl;
return 0;
}
I am getting 11 <--The Result. But actually the result is 11.4, Can someone please help me to understand the point please.
You are doing integer arithmetic . All operands are integers, which meand all operations will be done using integer operations. And for integer division 2/5
is equal to zero.
Use floating point value all over instead:
double arithmetic_operation = (4.+5.)+9.*2.-4.+2./5.+1.-13.;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.