Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <locale.h>
  4.  
  5. main()
  6. {
  7. setlocale (LC_ALL, "rus");
  8.  
  9. int number_account = 0;
  10. float start_balance, TotalCost, TotalCredit, ExtendOfCredit, NewBalance, Balance;
  11.  
  12. while (number_account != -1)
  13. {
  14. printf("Number account - ");
  15. scanf("%d", &number_account);
  16. printf("start_balance: ");
  17. scanf("%f", &start_balance);
  18. printf("TotalCost: ");
  19. scanf("%f", &TotalCost);
  20. printf("TotalCredit: ");
  21. scanf("%f", &TotalCredit);
  22. printf("ExtendOfCredit: ");
  23. scanf("%d", &ExtendOfCredit);
  24. NewBalance = start_balance + TotalCost - TotalCredit;
  25.  
  26. if (NewBalance > ExtendOfCredit)
  27. {
  28. printf("number_account: %d", number_account);
  29. printf("ExtendOfCredit: %.2f", ExtendOfCredit);
  30. printf("Balance: %.2fn n", Balance = start_balance + TotalCredit);
  31. }
  32. }
  33. system("PAUSE");
  34. }
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38.  
  39. // прочтем все символы до новой строки
  40. // вернем (для любопытных) их количество
  41. // или EOF (для анализа конца файла (это уже не пустое любопытство))
  42. static int
  43. skip()
  44. {
  45. int c, n = 0;
  46.  
  47. if (!feof(stdin)) // убедимся, что нужно читать
  48. while ((c = getchar()) != EOF) {
  49. n++;
  50. if (c == 'n')
  51. return n;
  52. }
  53. return EOF;
  54. }
  55.  
  56. int
  57. main ()
  58. {
  59. int a, b, i = 0, rc;
  60.  
  61. while (rc != EOF) {
  62. printf ("Enter a,b: "); fflush(stdout);
  63. rc = scanf("%d%d",&a,&b);
  64. printf ("rc = %d a = %d b = %dn", rc,a,b);
  65. #if ERRDEMO
  66. if (rc == 2)
  67. i = 0;
  68. else if (++i > 5)
  69. break;
  70. #else
  71. if (rc != EOF)
  72. if (rc != 2) {
  73. printf ("Input error rc = %dn",rc);
  74. printf ("skip %d charactersnTry again ",rc = skip());
  75. }
  76. #endif
  77. }
  78.  
  79. exit (0);
  80. }
  81.  
  82. gcc a.c
  83.  
  84. gcc -DERRDEMO a.c
  85.  
  86. avp@avp-xub11:~/hashcode$ gcc a.c -DERRDEMO
  87. avp@avp-xub11:~/hashcode$ ./a.out
  88. Enter a,b: 1 2
  89. rc = 2 a = 1 b = 2
  90. Enter a,b: 3 a
  91. rc = 1 a = 3 b = 2
  92. Enter a,b: rc = 0 a = 3 b = 2
  93. Enter a,b: rc = 0 a = 3 b = 2
  94. Enter a,b: rc = 0 a = 3 b = 2
  95. Enter a,b: rc = 0 a = 3 b = 2
  96. Enter a,b: rc = 0 a = 3 b = 2
  97. avp@avp-xub11:~/hashcode$ gcc a.c
  98. avp@avp-xub11:~/hashcode$ ./a.out
  99. Enter a,b: 1 2
  100. rc = 2 a = 1 b = 2
  101. Enter a,b: 3 a
  102. rc = 1 a = 3 b = 2
  103. Input error rc = 1
  104. skip 2 characters
  105. Try again Enter a,b: 3 4
  106. rc = 2 a = 3 b = 4
  107. Enter a,b: 5 6f
  108. rc = 2 a = 5 b = 6
  109. Enter a,b: rc = 0 a = 5 b = 6
  110. Input error rc = 0
  111. skip 2 characters
  112. Try again Enter a,b: 5 6
  113. rc = 2 a = 5 b = 6
  114. Enter a,b: rc = -1 a = 5 b = 6
  115. avp@avp-xub11:~/hashcode$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement