1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <cstdio>
#include <cmath>
bool getTwoInts(int &numerator, int &denominator);
void printDivision(int numerator, int denominator);
int main()
{
int numerator, denominator;
getTwoInts(numerator, denominator);
printDivision(numerator, denominator);
return 0;
}
bool getTwoInts(int &numerator, int &denominator)
{
int num, den;
int scanfResult;
printf("Please enter an integer numerator and denominator\n");
printf("e.g. 12 and 2\n");
scanfResult = scanf("%d %d", &num, &den);
if(scanfResult == 0) {
printf("The numerator was garbage, discarding\n");
scanf("%*s");
scanf("%*s");
return false;
} else if(scanfResult == 1) { // <---
printf("The denominator was garbage, discarding\n");
scanf("%*s");
return false;
}
numerator = num;
denominator = den;
return true; // <--- ????
}
void printDivision(int numerator, int denominator)
{
int result;
int remainder;
result = numerator/denominator;
printf("%d divided by %d is %d\n", numerator, denominator, result); // <---
remainder = numerator%denominator;
printf("The remainder is %d", remainder);
}
|