what am I doing wrong?
Thought a lot and cant see what is the problem with this code...
[c]
#include <stdio.h>
#include <ctype.h>
#define MAX(x, y) ( (x) > (y) ) ? (x) : (y)
#define MIN(x, y) ( (x) < (y) ) ? (x) : (y)
int
main(void)
{
int r1, r2, sum, i;
float res, min, max;
char str1[256], str2[256], c;
while (fgets(str1, 256, stdin) &&
fgets(str2, 256, stdin)) {
r1 = r2 = 0;
for (i = 0; str1[i]; ++i) {
c = tolower(str1[i]);
if (c >= 'a' && c <= 'z')
r1 += (c - 'a'+1);
}
for (i = 0; str2[i]; ++i) {
c = tolower(str2[i]);
if (c >= 'a' && c <= 'z')
r2 += (c - 'a'+1);
}
while (r1 > 9) {
sum = 0;
while (r1 > 0) {
sum += r1%10;
r1 /= 10;
}
r1 = sum;
}
while (r2 > 9) {
sum = 0;
while (r2 > 0) {
sum += r2%10;
r2 /= 10;
}
r2 = sum;
}
min = (float) MIN(r1, r2);
max = (float) MAX(r1, r2);
res = 100.0 * (min / max);
printf("%.2f\n", res);
}
return 0;
}
[/c]
thanks
