Skip to main content
deleted 102 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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

  1. Indentation

    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. An example of such a function that can be reused over and over again would be,

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

    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.

An example of such a function that can be reused over and over again would be:

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

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. An example of such a function that can be reused over and over again would be,

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

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.

An example of such a function that can be reused over and over again would be:

    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;
    }
added 80 characters in body
Source Link

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. An example of such a function that can be reused over and over again would be,  

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

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

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. An example of such a function that can be reused over and over again would be,  

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

Source Link

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