Skip to content

Instantly share code, notes, and snippets.

@hamlim
Created October 21, 2014 16:33
Show Gist options
  • Save hamlim/7a862aa8dcb3adc2cb5d to your computer and use it in GitHub Desktop.
Save hamlim/7a862aa8dcb3adc2cb5d to your computer and use it in GitHub Desktop.
whats wrong here?
#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