+ 1

7 or 9.375

when i run this code the compiler give me the answer 7 but when i calculate it the result = 9.375 what is the right answer? #include <iostream> using namespace std; int main() { int x=3/2*4+3/8+3; cout<<x<<endl; return 0; }

9th Jun 2018, 10:18 PM
Ztujjar
Ztujjar - avatar
2 odpowiedzi
+ 4
you need to use quite a bit of type-casting and store the result in a double to get your expected result.
10th Jun 2018, 1:04 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
0
i am still getting the same result 7 #include <iostream> using namespace std; int main() { float x; x=3/2*4+3/8+3; cout<<x<<endl; return 0; }
9th Jun 2018, 11:04 PM
Ztujjar
Ztujjar - avatar