Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int withdraw;
  6. int money[2];
  7. int n=0,p;
  8. int saldis;
  9. int i;
  10.  
  11. void valinnat();
  12. void vaihtoehdot();
  13. void lueJotain (void);
  14. int lueintti (void);
  15.  
  16. int main(void)
  17. {
  18. char tilinum [112];
  19. FILE *tili;
  20. char pinni [1234];
  21. char checkPIN[1234];
  22. int paatti;
  23.  
  24.  
  25. do{
  26. printf("\n Enter account number:");
  27. fgets(tilinum, 112 , stdin);
  28. if ( tilinum [ strlen(tilinum) -1] == '\n')
  29. tilinum [ strlen(tilinum) -1] = '\0';
  30. else lueJotain();
  31.  
  32. strcat (tilinum, ".tili");
  33.  
  34. if( (tili = fopen( tilinum, "r"))!=NULL){
  35. printf(" Enter pin-code:");
  36.  
  37. fgets(pinni, 1234 , stdin);
  38.  
  39. if ( pinni [ strlen(pinni) -1] == '\n')
  40. pinni [ strlen(pinni) -1] = '\0';
  41. else lueJotain();
  42.  
  43. fgets(checkPIN, 1234 , tili);
  44.  
  45. do {
  46.  
  47. if ( checkPIN [ strlen(checkPIN) -1] == '\n')
  48. checkPIN [ strlen(checkPIN) -1] = '\0';
  49. if ( checkPIN [ strlen(checkPIN) -1] == '\r')
  50. checkPIN [ strlen(checkPIN) -1] = '\0';
  51.  
  52. if ((paatti = strcmp(pinni, checkPIN)) == 0){
  53. fscanf(tili, "%d", &saldis);
  54. valinnat();
  55. }else
  56. printf(" Incorrect, Try again");
  57. }while ( !paatti );
  58.  
  59.  
  60. }else{
  61. printf("\n Account is closed");
  62. }
  63.  
  64. }while(1);
  65.  
  66. return 0;
  67. }
  68.  
  69. void lueJotain(void){
  70. while (fgetc(stdin) != '\n');
  71. }
  72.  
  73. void valinnat() {
  74. while (i !=3)
  75. {
  76. printf("Tervetuloa\n");
  77. printf("1. Katso saldo\n");
  78. printf("2. Nosta rahaa\n");
  79. printf("3. Lopeta\n");
  80. printf("Syota valinta: ");
  81. scanf("%d", &i);
  82. vaihtoehdot();
  83.  
  84. }
  85. }
  86. void vaihtoehdot() {
  87.  
  88. switch(i)
  89. {
  90. case 1:
  91. printf("\nSaldosi on: %d ", saldis);
  92. break;
  93.  
  94. case 2:
  95. printf("\n Syota nostosumma: ");
  96. scanf("%d", &withdraw);
  97. while (withdraw >20 || withdraw != 30 || withdraw < 1000){
  98. money[0]=50;
  99. money[1]=20;
  100. p=withdraw / money[n];
  101. withdraw=withdraw % money[n];
  102. printf("Keraa seteleita %2d : %2d \n", money[n],p);
  103. n++;
  104.  
  105. }
  106. break;
  107.  
  108. case 3:
  109. printf("Kiitos kaynnista\n");
  110. break;
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement