Created
August 4, 2020 16:47
-
-
Save hareom284/4044a4a571048029c9c1ff8780f481c4 to your computer and use it in GitHub Desktop.
Harvard summer 2020 week 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<cs50.h> | |
#include<math.h> | |
int main(void) | |
{ float dollars=0; | |
do | |
{ | |
dollars = get_float("Chang owned:"); | |
}while(dollars<0); | |
int cents = round(dollars*100); | |
int count=0; | |
while(cents!=0) | |
{ | |
if(cents>24) | |
{ | |
cents=cents-25; | |
count++; | |
} | |
else if(cents>9) | |
{ | |
cents=cents-10; | |
count++; | |
} | |
else if(cents>4) | |
{ | |
cents=cents-5; | |
count++; | |
} | |
else | |
{ | |
count+=cents; | |
cents=0; | |
} | |
} | |
printf("%d",count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment