+ 2

I need help 😭 I'm new to c++ and I'm stuck

I try to print a floating point number, for example double number = 1/2; cout <<number ;//output is 0 instead of 0.5 Why does the compiler take the whole number and keeps out the decimals But on the other hand, double number = 0.5;// output is 0.5 I'm confused I KNOW THIS IS MERE BASICS BUT PLS DON'T SKIP 🙏

16th Mar 2022, 7:10 PM
Samuel Mbah
3 Respuestas
+ 3
FF9900 thanks for the help, it helped me solve my third challenge, ticket office in c++
16th Mar 2022, 11:42 PM
Samuel Mbah
0
#include <iostream> using namespace std; int main() { float a=1.0/2.0; cout<<"input one number "<<endl; cout<<a; //Output=0.5 return 0; }
17th Mar 2022, 8:52 AM
Uzair Saeed