Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.46 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS // wyłączenie ostrzeżeń kompilatora
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define TEN 10
  5. #define FIVE 5
  6. #define TWO 2
  7.  
  8. typedef struct money_t{ //definicja struktury, która przechowuje ilość wystąpień danego nominału
  9.     int two;
  10.     int five;
  11.     int ten;
  12. }money_t;
  13.  
  14. int show_result(const money_t* m) { //funkcja wypisująca dane ze struktury
  15.     if (m->two || m->five || m->ten) {
  16.         printf("Kwote mozna rozlozyc na: ");
  17.         if (m->two) printf(" %d * 2zl %c", m->two, m->five||m->ten ? '+' : ' ');
  18.         if (m->five) printf(" %d * 5zl %c", m->five, m->ten? '+':' ');
  19.         if (m->ten) printf(" %d * 10zl ", m->ten);
  20.         printf("\n");
  21.         return 1;
  22.     }
  23.     else {
  24.         printf("Kwoty nie da sie rozlozyc!\n");
  25.         return 0;
  26.     }
  27. }
  28.  
  29. void sum_money(const money_t* d, const money_t* r, money_t* s) {
  30.     if (r != NULL && d != NULL) {
  31.         s->two = d->two + r->two;
  32.         s->five = d->five + r->five;
  33.         s->ten = d->ten + r->ten;
  34.     }
  35.     else if(r == NULL){
  36.         *s = *d;
  37.     }
  38.     else if (d == NULL) {
  39.         *s = *r;
  40.     }
  41. }
  42.  
  43. void reset_money(money_t* s) {
  44.     s->two = s->five = s->ten = 0;
  45. }
  46.  
  47. int main( void ) {
  48.     int money, temp_money = 0, temp_rest = 0, counter = 0, rest = 0; //deklaracja zmiennych
  49.     char c;
  50.    
  51.     money_t dozens_s = { 0 }, rest_s = { 0 }, sum = { 0 };
  52.     money_t* p_dozens_s = &dozens_s, * p_rest_s = &rest_s;
  53.  
  54.     printf("Podaj kwote:");//komunikat
  55.     scanf("%d", &money);//pobranie kwoty od użytkownika
  56.     while ((c = getchar()) != '\n' && c != EOF);//oczyszczenie bufora
  57.     if (money <= 0) { //jeśli kwota ujemna lub równa zeru
  58.         printf("Kwota nie moze byc ujemna lub rowna zeru.\nKoniec programu.\n");
  59.         getchar();
  60.         exit(0);
  61.     }
  62.     else if (money == 1 || money == 3) {
  63.         printf("Kwoty nie da sie rozlozyc!\nKoniec programu.\n");
  64.         getchar();
  65.         exit(0);
  66.     }
  67.     else {
  68.         switch (money % 10) {
  69.         case 0://kwota jest podzielna przez 10 i nie ma reszty z dzielenia
  70.            
  71.             p_rest_s = NULL;//ten wskaźnik może wskazywać null, ponieważ struktura na którą wskazuje nie będzie użyta
  72.            
  73.  
  74.  
  75.  
  76.             break;
  77.         default://kwota przy dzieleniu przez 10 daje reszte
  78.             if (money > 10) {
  79.                 rest = (money % 10) + TEN;
  80.                 money -= TEN;
  81.                 if (money) {//jeśli dalej jest podzielna przez 10
  82.  
  83.  
  84.  
  85.  
  86.                 }
  87.                 else {//jeśli zero to rozbijana jest tylko reszta
  88.                     p_dozens_s = NULL;
  89.  
  90.  
  91.  
  92.  
  93.                 }
  94.             }
  95.             else {
  96.                 rest = money % 10;//rozbijanie samej reszty mniejszej od 10
  97.                 p_dozens_s = NULL;
  98.  
  99.  
  100.  
  101.  
  102.  
  103.             }
  104.             break;
  105.         }
  106.         getchar();
  107.     }
  108.     return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement