File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include "main.h"
2+ #include <stdio.h>
3+ #include <stdlib.h>
4+ #include <string.h>
5+ /**
6+ * main - main function
7+ * @argc: argumentc
8+ * @argv: vector of arguments
9+ *Return: always 0
10+ */
11+ int main (int argc , char * argv [])
12+ {
13+ int coins = 0 ;
14+
15+ if (argc == 2 )
16+ {
17+ if (strchr (argv [argc - 1 ], '-' ))
18+ {
19+ printf ("0\n" );
20+ return (1 );
21+ }
22+ int money ;
23+
24+ money = atoi (argv [argc - 1 ]);
25+
26+ while (money > 0 )
27+ {
28+ if (money % 25 == 0 )
29+ {
30+ money -= 25 ;
31+ } else if (money % 10 == 0 )
32+ {
33+ money -= 10 ;
34+ } else if (money % 5 == 0 )
35+ {
36+ money -= 5 ;
37+ } else if (money % 2 == 0 )
38+ {
39+ money -= 2 ;
40+ } else
41+ {
42+ money -- ;
43+ }
44+ coins ++ ;
45+ }
46+ printf ("%d\n" , coins );
47+ return (0 );
48+ }
49+ printf ("Error\n" );
50+ return (1 );
51+ }
Original file line number Diff line number Diff line change 1+ #include "main.h"
2+ #include <stdio.h>
3+ #include <stdlib.h>
4+ #include <ctype.h>
5+ #define UNUSED (x ) (void)(x)
6+ /**
7+ * StringCheck - checks string
8+ * @s: string to check
9+ * Return: boolean
10+ */
11+ int StringCheck (char * s )
12+ {
13+ int i = 0 ;
14+
15+ for (; s [i ] != '\0' ; i ++ )
16+ {
17+ if (!isdigit (s [i ]))
18+ {
19+ return (0 );
20+ }
21+ }
22+ return (1 );
23+ }
24+ /**
25+ * main - main function
26+ * @argc: argumentc
27+ * @argv: vector of arguments
28+ *Return: always 0
29+ */
30+ int main (int argc , char * argv [])
31+ {
32+ int i ;
33+ int result = 0 ;
34+
35+ if (argc > 1 )
36+ {
37+ for (i = 1 ; i < argc ; i ++ )
38+ {
39+ if (StringCheck (argv [i ]))
40+ {
41+ result += atoi (argv [i ]);
42+ }
43+ else
44+ {
45+ printf ("Error\n" );
46+ return (1 );
47+ }
48+ }
49+ printf ("%d\n" , result );
50+ return (0 );
51+ }
52+ else
53+ {
54+ printf ("%d\n" , 0 );
55+ return (1 );
56+ }
57+
58+ }
You can’t perform that action at this time.
0 commit comments