• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Feb 17th, 2020 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. CODE::
2.
3. #include<stdio.h>
4. //defining constants
5. #define DOLLAR 100
6. #define QUARTER 25
7. #define DIME 10
8. #define NICKEL 5
9. #define PENNIES 1
10.
11. //converting method
12. void ExactChange(int userTotal,int coinVals[])
13. {
14.
15.
16. //checking dollars
17. if (userTotal >=100)
18. {
19.
20.
21. coinVals[0]=userTotal/DOLLAR;
22. userTotal=userTotal-(100*coinVals[0]);
23.
24.
25. }
26. //checking quarters
27. if (userTotal >=25)
28. {
29.
30.
31. coinVals[1]=userTotal/QUARTER;
32. userTotal=userTotal-(25*coinVals[1] );
33.
34.
35. }
36. //checking dimes
37. if (userTotal >=10)
38. {
39.
40.
41. coinVals[2]=userTotal/DIME;
42. userTotal=userTotal-(10*coinVals[2]);
43.
44.
45. }
46. //checking nickels
47. if (userTotal >=5)
48. {
49.
50.
51. coinVals[3]=userTotal/NICKEL;
52. userTotal=userTotal-(5*coinVals[3]);
53.
54.
55. }
56. //checking pennies
57. if (userTotal >=1)
58. {
59.
60.
61. coinVals[4]=userTotal/PENNIES;
62. userTotal=userTotal-coinVals[4];
63.
64.
65. }
66.
67. }
68. //main method
69. int main() {
70.
71. //defining the variables
72. int amount;
73.
74. //asking for input
75. printf("Enter the amount in cents :");
76. //reading the input
77. scanf("%d",&amount);
78. //validating the input
79. if(amount<1)
80. {
81.
82.
83. //printing the message
84. printf("No change..!");
85.
86.
87. }
88. //when the input is >0
89. else
90. {
91.
92.
93. int coinVals[5]={0,0,0,0,0};
94. ExactChange(amount,coinVals);
95. //checking dollars
96. if (coinVals[0]>0)
97. {
98.
99.
100. //printing dollars
101. printf("%d Dollar",coinVals[0]);
102. if(coinVals[0]>1) printf("s");
103.
104. }
105. //checking quarters
106. if (coinVals[1]>0)
107. {
108.
109. //printing quarters
110. printf(" %d Quarter",coinVals[1]);
111. if(coinVals[1]>1) printf("s");
112.
113. }
114. //checking dimes
115. if (coinVals[2]>0)
116. {
117.
118. //printing dimes
119. printf(" %d Dime",coinVals[2]);
120. if(coinVals[2]>1) printf("s");
121.
122. }
123. //checking nickels
124. if (coinVals[3]>0)
125.
126. {
127.
128. //prinitng nickels
129. printf(" %d Nickel",coinVals[3]);
130. if(coinVals[3]>1) printf("s");
131.
132. }
133. //checking pennies
134. if (coinVals[4]>0)
135. {
136.
137. //printing pennies
138. printf(" %d Penn",coinVals[4]);
139. if(coinVals[4]>1) printf("ies");
140. else printf("y");
141.
142. }
143.
144. }
145. //end of main method
146.
147.
148. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Top