Can you glance through my code and tell if I made any mistakes? Or if it is possible to make program more readable, compact, etc.
The program shows the maximum out of four entered into input. Thanks!
Code:
#include <stdio.h>
int answer;
int compare(int ent1, int ent2, int ent4); // Declaring prototype for the function
FILE *csci;
int main(void) {
int i = 1;
int result;
int ent1, ent2, ent3, ent4; // Declaring scanf variables. "ent" stands for enter.
csci = fopen("csci.txt", "w"); // Creating a csci.txt file
for (i == 1; i <= 4; ++i) {
printf("Enter four integers: "); scanf("%d %d %d %d", &ent1, &ent2, &ent3, &ent4);
fprintf(csci, "Integers Entered: "); fprintf(csci, "%d %d %d %d", ent1, ent2, ent3, ent4);
result = compare(ent1, ent2, ent3, ent4); //Using the function
printf("The biggest number is: %d \n", result);
fprintf(csci, "The biggest is: %d \n", result);
}
fclose(csci);
return (0);
}
int compare(int num1, int num2, int num3, int num4) {
if (num1 > num2 && num1 > num3 && num1 > num4) {
answer = num1;
return answer;
}
else if (num2 > num1 && num2 > num3 && num2 > num4) {
answer = num2;
return answer;
}
else if (num3 > num1 && num3 > num2 && num3 > num4) {
answer = num3;
return answer;
}
else if (num4 > num2 && num4 > num3 && num4 > num1) {
answer = num4;
return answer;
}
}