File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <cs50.h>
3
+ #include <math.h>
4
+
5
+ int main (void )
6
+ {
7
+ //Variables declaration
8
+ float input = 0 ;
9
+ printf ("O hai! " );
10
+
11
+ //Ask user for input
12
+ do
13
+ {
14
+ printf ("How much change is owned?\n" );
15
+ input = GetFloat ();
16
+ }while (input < 0 );
17
+
18
+
19
+ //Process input
20
+ int count = 0 ; //to count how many coins
21
+
22
+ //Process dollars
23
+ input = input * 100 ;
24
+ int cinput = (int ) round (input );
25
+
26
+ // Process cents
27
+ do
28
+ {
29
+ if (cinput >= 25 ) cinput -= 25 ;
30
+ else if (cinput < 25 && cinput >= 10 ) cinput -= 10 ;
31
+ else if (cinput < 10 && cinput >= 5 ) cinput -= 5 ;
32
+ else if (cinput < 5 && cinput > 0 ) { cinput -= 1 ; };
33
+ count ++ ;
34
+
35
+ }while (cinput > 0 );
36
+
37
+ // Print number of coins
38
+ printf ("%d\n" , count );
39
+ }
You can’t perform that action at this time.
0 commit comments