Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Courses
csci206_lecture_examples
Commits
791d2511
Commit
791d2511
authored
Jan 22, 2014
by
Alan Marchiori
Browse files
added lec04
parent
7817b51f
Changes
3
Hide whitespace changes
Inline
Side-by-side
section01/Lec04/Activity3MoreCPractice.pdf
0 → 100644
View file @
791d2511
File added
section01/Lec04/Lec04 - PH1_1 - 1_3.odp
0 → 100644
View file @
791d2511
File added
section01/Lec04/change.c
0 → 100644
View file @
791d2511
#include <stdio.h>
#include <stdlib.h>
struct
change
{
int
quarters
;
int
dimes
;
int
nickels
;
int
pennies
;
};
struct
change
*
make_change
(
float
amount
)
{
int
cents
=
amount
*
100
;
struct
change
*
c
=
malloc
(
sizeof
(
*
c
));
c
->
quarters
=
0
;
c
->
dimes
=
0
;
c
->
nickels
=
0
;
c
->
pennies
=
0
;
while
(
cents
>
0
){
if
(
cents
>
25
){
c
->
quarters
++
;
cents
-=
25
;
}
else
if
(
cents
>
10
){
c
->
dimes
++
;
cents
-=
10
;
}
else
if
(
cents
>
5
){
c
->
nickels
++
;
cents
-=
5
;
}
else
{
c
->
pennies
=
cents
;
cents
=
0
;
}
}
return
c
;
}
void
print_change
(
struct
change
*
c
)
{
printf
(
"%d quarters, %d dimes, %d nickels, %d pennies
\n
"
,
c
->
quarters
,
c
->
dimes
,
c
->
nickels
,
c
->
pennies
);
}
int
main
(
void
){
struct
change
*
c
;
float
amount
;
printf
(
"amount: $"
);
scanf
(
"%f"
,
&
amount
);
c
=
make_change
(
amount
);
print_change
(
c
);
free
(
c
);
c
=
NULL
;
// don't leave dangling pointer
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment