c program to allow user to change there already set 4 digit pin -
- enter pin , verify correct
- change pin
- display number of times pin entered (i) (ii) incorrectly
- exit program
i having problems option 2 in question above supposed following: if select option 2, should allowed change pin. program should verify original pin first. when enter new pin, program must verify new pin asking customer re-enter new pin. verify new pin entered correct , no errors made. if there differences , verification fails, program must display appropriate error message , original pin should remain same.
my problem arises when user entering new pin, 1. pin must 4 digits long 2. if user enters pin wrong when entering new pin, original pin must remain same. if enter new pin right new pin must change pin. have posted code have far option 2.
if question not clear please ask me questions.
case 2: { //ask user enter current pin printf("please enter current pin \n"); scanf("%d",¤t_pin); if(current_pin != 1234) { //if pin entered not same 1234-print error printf("incorrect pin \n"); unsuccessful ++; break; }//end if else { successful++; //ask user enter new pin printf("please enter new pin: \n"); scanf("%d",&new_pin); } //end else //set new pin current pin current_pin = new_pin: //check if pin 4 digits long if(current_pin>999 && current_pin<10000) { //ask user re enter new pin printf("please re-enter new pin: \n"); scanf("%d",&new_pin); printf("your new pin %d", new_pin); //set new pin current pin current_pin = new_pin: } else { printf("incorrect entry- pin must 4 digits , cannot start 0"); } new_pin=current_pin; break; }
i know code sloopy hope can make sense of it. know trying can't it.
****edit**** ok understand have made of confused. maybe should reword question. , break down sections. , if easier can post full code program.
i want user enter current pin if program running first time has been assigned value 1234. if user has gone through process current pin pin have changed to.
the pin new pin must 4 digits
this might pushing if user enters letter program go infinite loop, there simple way around this.
this little odd:
printf("please enter current pin \n"); scanf("%d",¤t_pin); if(current_pin != 1234) {
is current_pin value stores user's pin? if you'll change when scanf. create new variable store result. this:
int value; scanf("%d",&value); if(current_pin != value) {
you seem doing lot:
current_pin = new_pin:
i admit i'm bit confused whether colon typo or don't understand.
however, shouldn't assignment until have checked value of new pin
//check if pin 4 digits long if(new_pin>999 && new_pin<10000) { int verified; //ask user re enter new pin printf("please re-enter new pin: \n"); scanf("%d",&verified); if(verified == new_pin)) { printf("your new pin %d", new_pin); //set new pin current pin current_pin = new_pin; // <--- place assign current_pin } else { //tell user there error } }
Comments
Post a Comment