And for c I get 0. How could it be??????Code:int a;
int b;
double c;
//in the course of the program I got a=492 and also b=492//
c=a/b;
Printable View
And for c I get 0. How could it be??????Code:int a;
int b;
double c;
//in the course of the program I got a=492 and also b=492//
c=a/b;
Apparently you don't have 492 for both a and b. Have you tried writing both values to the console just before the calculation?
Looks a lot like 1 to me. However, notice that you're performing integer division. To do floating point division, you'll need something like this:Code:int main()
{
int a = 492;
int b = 492;
double c=a/b;
std::cout << c << std::endl;
return 0;
}
Code:int main()
{
int a = 36;
int b = 492;
double c=(float)a/b;
std::cout << c << std::endl;
return 0;
}
If you're assigning to a double, cast to a double. And use static_cast:
double c = static_cast<double>(a)/b;
did you try restarting your computer? that's usually what I do