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;
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?
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
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 I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
If you're assigning to a double, cast to a double. And use static_cast:
double c = static_cast<double>(a)/b;
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
did you try restarting your computer? that's usually what I do
"What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)