Created
October 21, 2014 16:33
-
-
Save hamlim/7a862aa8dcb3adc2cb5d to your computer and use it in GitHub Desktop.
whats wrong here?
This file contains 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 <iostream> | |
using namespace std; | |
int change(int n){ | |
int val = n; | |
int num = 0; | |
while(val > 0){ | |
if(val > 50){ | |
num = num + 1; | |
val = val-50; | |
cout<<"50"<<endl; | |
} else if (val > 25){ | |
num = num + 1; | |
val = val - 25; | |
cout<<"25"<<endl; | |
} else if (val > 10){ | |
num = num + 1; | |
val = val-10; | |
cout<<"10"<<endl; | |
} else if (val > 5){ | |
num = num + 1; | |
val = val-5; | |
cout<<"5"<<endl; | |
} else { | |
//val > 1 | |
num = num + 1; | |
val = val -1; | |
cout<<"1"<<endl; | |
} | |
} | |
return num; | |
} | |
int main (void){ | |
int value; | |
cin >> value; | |
cout<<change(value)<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment