I have a problem with the following code:
#include <stdio.h>
#include <iostream>
int main ()
{
int a, b;
printf("Please type in your number a: ");
scanf_s("%d", &a);
printf("Please type in your number b: ");
scanf_s("%d", &b);
printf("Solution 1 (divide and modulus): %f\n", a / b + a % b);
printf("Solution 2 (cast): %f", (float) a / b);
std::cin.get();
std::cin.get();
return 0;
}
I want my program to read two integers and i want to use two different methods to divide them without round-off errors. Sincerly the first solution does not work. The output are just zeros. I don’t know where the problem is.
The result of
a/b + a%bis aninteger(%d), but you are printing out afloat(%f).