Skip to main content
1 of 3

Some of the suggestions that I think you might find useful are,

  1. Indentation

  2. Functions are great because you get to reuse the code. I noticed that you have two separate functions to perform validations. Instead you could simply pass the value to be validated as a parameter,

    int main(int argc, char *argv[]){ int validate_state=0; //(1)----------Validating account number validate_state=0; validate_state=validate(account_number, 3); if (validate_state==0) printf("Invalid Account Number");

            //(2)----------Validating Pin number
            validate_state=0;
            validate_state=validate(pin_number, 3);
            if (validate_state==0) printf("Invalid Pin Number");
    
    
            //(n)----------Validating n'th value with k attempts
            validate_state=0;
            validate_state=validate(n_value, k);
            if (validate_state==0) printf("Invalid Some Number");
    

    }

    int validate (int expected_val, int retries){ int input; scanf("%d", &input); // maybe fgets as the prev comment while(retries>0){ if (input==expected_val){ return 1; }else{ scanf("%d", &input); retries --; }
    } return 0; }