HEY there,
Just wrote my massive question which I lost when the page refreshed. so annoying. but in short:
1. How do I ensure that only 3 values are inputted into the system? I thought I could do it like this: while(scanf("%d%d%d",&x,&y,&z)==3)
doesn't seem to be working
2. How do I allow an infinite number of inputs??? (e.g: running sum of numbers).
3. What's wrong with my code?! need to find max of 3 values, by using function.
Thanks guys!
Code:
#include <stdio.h>
#include <stdlib.h>
int int_max_3(int, int, int);
int
main(int argc, char **argv) {
int x, y, z;
printf("Enter three ints: ");
while(scanf("%d%d%d",&x,&y,&z)==3)
printf("x=%d y=%d z=%d", x, y, z);
int answer = int_max_3(x, y, z);
printf("The answer is %d.", answer);
return 0;
}
int
int_max_3(int a, int b, int c) {
int answer;
if ((a>b) && (b>c))
answer = a;
else if ((b>a) && (b>c))
answer = b;
else
answer = c;
return answer;
}