Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS // wyłączenie ostrzeżeń kompilatora
- #include <stdio.h>
- #include <stdlib.h>
- #define TEN 10
- #define FIVE 5
- #define TWO 2
- typedef struct money_t{ //definicja struktury, która przechowuje ilość wystąpień danego nominału
- int two;
- int five;
- int ten;
- }money_t;
- int show_result(const money_t* m) { //funkcja wypisująca dane ze struktury
- if (m->two || m->five || m->ten) {
- printf("Kwote mozna rozlozyc na: ");
- if (m->two) printf(" %d * 2zl %c", m->two, m->five||m->ten ? '+' : ' ');
- if (m->five) printf(" %d * 5zl %c", m->five, m->ten? '+':' ');
- if (m->ten) printf(" %d * 10zl ", m->ten);
- printf("\n");
- return 1;
- }
- else {
- printf("Kwoty nie da sie rozlozyc!\n");
- return 0;
- }
- }
- void sum_money(const money_t* d, const money_t* r, money_t* s) {
- if (r != NULL && d != NULL) {
- s->two = d->two + r->two;
- s->five = d->five + r->five;
- s->ten = d->ten + r->ten;
- }
- else if(r == NULL){
- *s = *d;
- }
- else if (d == NULL) {
- *s = *r;
- }
- }
- void reset_money(money_t* s) {
- s->two = s->five = s->ten = 0;
- }
- int main( void ) {
- int money, temp_money = 0, temp_rest = 0, counter = 0, rest = 0; //deklaracja zmiennych
- char c;
- money_t dozens_s = { 0 }, rest_s = { 0 }, sum = { 0 };
- money_t* p_dozens_s = &dozens_s, * p_rest_s = &rest_s;
- printf("Podaj kwote:");//komunikat
- scanf("%d", &money);//pobranie kwoty od użytkownika
- while ((c = getchar()) != '\n' && c != EOF);//oczyszczenie bufora
- if (money <= 0) { //jeśli kwota ujemna lub równa zeru
- printf("Kwota nie moze byc ujemna lub rowna zeru.\nKoniec programu.\n");
- getchar();
- exit(0);
- }
- else if (money == 1 || money == 3) {
- printf("Kwoty nie da sie rozlozyc!\nKoniec programu.\n");
- getchar();
- exit(0);
- }
- else {
- switch (money % 10) {
- case 0://kwota jest podzielna przez 10 i nie ma reszty z dzielenia
- p_rest_s = NULL;//ten wskaźnik może wskazywać null, ponieważ struktura na którą wskazuje nie będzie użyta
- break;
- default://kwota przy dzieleniu przez 10 daje reszte
- if (money > 10) {
- rest = (money % 10) + TEN;
- money -= TEN;
- if (money) {//jeśli dalej jest podzielna przez 10
- }
- else {//jeśli zero to rozbijana jest tylko reszta
- p_dozens_s = NULL;
- }
- }
- else {
- rest = money % 10;//rozbijanie samej reszty mniejszej od 10
- p_dozens_s = NULL;
- }
- break;
- }
- getchar();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement