#include <iostream>
using namespace std;
int main()
{
double var1 = 0;
var1 = 2/10;
cin.ignore();
cin.get();
return 0;
}
Its not setting var1 to .2 it is keeping it at 0. wth?
it does 10/2 = 5, but then it does 2/10 = 0.
#include <iostream>
using namespace std;
int main()
{
double var1 = 0;
var1 = 2/10;
cin.ignore();
cin.get();
return 0;
}
Its not setting var1 to .2 it is keeping it at 0. wth?
it does 10/2 = 5, but then it does 2/10 = 0.
Apparently using decimal format is required. Never mind
Yup, your program was doing integer division, therefore 2/5 is 0 but 2.0/5 will give you the result you desire.
I know you said it's solved but just to clarify for you. Dividing 2 integers gives an integer result (0) which is then assigned to the double. You found the solution already.
Thanks for replys
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.