1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 64
int get_euro_divmod(int f, int i) ;
int get_cents_divmod(int f, int i) ;
main(int argc, char argv[]) {
int euro_500=0, euro_200=0, euro_100=0,euro_50=0,euro_20=0,euro_10=0, euro_5=0;
int euro_2=0, euro_1=0 ;
int cents_50=0, cents_20=0, cents_10=0, cents_5=0, cents_2=0, cents_1=0 ;
int euro_entry, cents_entry ;
char entry[MAXSIZE] ;
char integer_part[]={} ;
char decimal_part[]={} ;
int c_entry, c_int_part, c_dec_part, bool ; // c_ == counter_
printf("Enter the Euros value:\n") ;
fgets(entry,MAXSIZE,stdin) ;
c_int_part = c_dec_part = bool= 0 ;
for (c_entry=0 ; c_entry < ((int) strlen(entry)) ; c_entry++) {
if (entry[c_entry] == '.') {
bool=1 ;
continue ;
}
if (bool == 0 ) {
integer_part[c_int_part]=entry[c_entry] ;
c_int_part++ ;
}
else if (bool == 1 ) {
decimal_part[c_dec_part]=entry[c_entry] ;
c_dec_part++ ;
}
}
integer_part[++c_int_part]='\0' ;
decimal_part[++c_dec_part]='\0' ;
//printf("%s.%s",integer_part,decimal_part) ;
euro_entry=strtol(integer_part,NULL,10) ;
cents_entry=strtol(decimal_part,NULL,10) ;
euro_500=get_euro_divmod(euro_entry,500) ;
euro_entry-=(get_euro_divmod(euro_entry,500) * 500 ) ;
euro_200=get_euro_divmod(euro_entry,200) ;
euro_entry-=(get_euro_divmod(euro_entry,200) * 200 ) ;
euro_100=get_euro_divmod(euro_entry,100) ;
euro_entry-=(get_euro_divmod(euro_entry,100) * 100 ) ;
euro_50=get_euro_divmod(euro_entry,50) ;
euro_entry-=(get_euro_divmod(euro_entry,50) * 50 ) ;
euro_20=get_euro_divmod(euro_entry,20) ;
euro_entry-=(get_euro_divmod(euro_entry,20) * 20 ) ;
euro_10=get_euro_divmod(euro_entry,10) ;
euro_entry-=(get_euro_divmod(euro_entry,10) * 10 ) ;
euro_5=get_euro_divmod(euro_entry,5) ;
euro_entry-=(get_euro_divmod(euro_entry,5) * 5 ) ;
euro_2=get_euro_divmod(euro_entry,2) ;
euro_entry-=(get_euro_divmod(euro_entry,2) * 2 ) ;
euro_1=get_euro_divmod(euro_entry,1) ;
euro_entry-=(get_euro_divmod(euro_entry,1) * 1 ) ;
cents_50=get_cents_divmod(cents_entry,50) ;
cents_entry-=(get_cents_divmod(cents_entry,50) * 50 ) ;
cents_20=get_cents_divmod(cents_entry,20) ;
cents_entry-=(get_cents_divmod(cents_entry,20) * 20 ) ;
cents_10=get_cents_divmod(cents_entry,10) ;
cents_entry-=(get_cents_divmod(cents_entry,10) * 10 ) ;
cents_5=get_cents_divmod(cents_entry,5) ;
cents_entry-=(get_cents_divmod(cents_entry,5) * 5 ) ;
cents_2=get_cents_divmod(cents_entry,2) ;
cents_entry-=(get_cents_divmod(cents_entry,2) * 2 ) ;
cents_1=get_cents_divmod(cents_entry,1) ;
cents_entry-=(get_cents_divmod(cents_entry,1) * 1 ) ;
printf("You musst have:\n500.00: %i\n200.00: %i\n100.00: %i\n 50.00: %i\n 20.00: %i\n 10.00: %i\n 5.00: %i\n 2.00: %i\n 1.00: %i\n 0.50: %i\n 0.20: %i\n 0.10: %i\n 0.05: %i\n 0.02: %i\n 0.01: %i\n",euro_500, euro_200, euro_100, euro_50, euro_20, euro_10, euro_5, euro_2, euro_1, cents_50, cents_20, cents_10, cents_5, cents_2,cents_1) ;
}
int get_euro_divmod(int f, int i) {
return f/i ;
}
int get_cents_divmod(int f, int i) {
return f/i ;
} |
Partager