My mistake! I thought it checked for the pin in the while loop. However, break will also do nothing, going straight to the break out of the switch statement. Thus you need to get the pin in the while loop.
My mistake! I thought it checked for the pin in the while loop. However, break will also do nothing, going straight to the break out of the switch statement. Thus you need to get the pin in the while loop.
break might work, I was thinking something along the lines of this:
But still, a modified version would be better.Code:for(;;) { printf( "This is not the correct PIN\n" ) ; printf( "Please re - enter your pin\n" ) ; scanf( "%d",&pin ) ; //re scan pin if(pin == 1234) break; printf( "This is not the correct PIN\n" ) ; printf( "Please re - enter your pin.You have one attempt left\n" ) ; scanf( "%d",&pin ) ; //re scan pin if(pin == 1234) break; printf( "This is not the correct PIN\n" ) ; printf( "You must re - start Program\n" ) ; scanf( "%d",&pin ) ; //re scan pin if(pin == 1234) break; printf( "Press 3 to exit\n" ) ; scanf( "%d",&exit) ; break ; }// end for
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Maybe a more flexible
Code:int count, max = 5; for(count = 1; count <= max; ++count) { printf("Enter PIN [attempt %d of %d]: ", count, max); scanf("%d", &pin); if(pin == 1234) { break; } printf("ERROR: PIN incorrect\n"); } if(pin != 1234) { printf("You have used up all attempts!\n"); printf("The PIN has been locked\n"); /* whatever */ }
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
thanks!!