Thread: Quick program check

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    6

    Post Quick program check

    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;
        }
    
    
    }

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    810
    Can you glance through my code and tell if I made any mistakes?
    Have you run enough tests to insure the code works correctly? Do YOU think the code works?

    Or if it is possible to make program more readable, compact, etc.
    Yes. Have you tried yourself?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a quick check for this function call
    By phillyflyers in forum C Programming
    Replies: 6
    Last Post: 04-17-2013, 11:18 PM
  2. Quick check
    By SofaWolf in forum C Programming
    Replies: 6
    Last Post: 06-26-2012, 12:53 PM
  3. Need a quick check
    By Aliaks in forum C++ Programming
    Replies: 7
    Last Post: 06-05-2009, 04:57 AM
  4. Quick input check question
    By Jozrael in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2009, 07:23 AM
  5. Quick check on reading in + using strings
    By advancedk in forum C Programming
    Replies: 2
    Last Post: 12-08-2008, 10:12 PM

Tags for this Thread