Correct Change I Comments
Comments
-
Sorry, I mistook nickels and pennies...
-
5, 4, 23 will result false !!!!!! it ca't be true 5*5 +4 = 24 ?????????????????
-
@Amboss, the challenge is to see if you can select the exact change from the coins you are given. So if you have 5 nickels, you can select 4 of them, add 4 pennies for a sum of 24 cents.
-
I've made the code, but when I run table below shows that all cases are correct EXCEPT that "Your Output" is incorrect, it's red.
I don't know why, I checked some made up cases manually on Eclipse. -
Кирилл, When given 7 nickels and 3 pennies, can you get 35 cents? Yes, you just select the nickels and ignore the pennies. Check your code to see what it returns.
-
Admin (?), I've make some changes, even few, but still, there is something wrong. Your example works, thanks for it!)
I'm just curious where I get lost. -
Кирилл. there's another example you're getting wrong. I think you should approach this problem a little differently. You can solve it with one if-else statement.
-
You can solve it with one if-else statement.
You're right. And only now it's shows "Correct". I have to say that with no mathematical help I won't do that. So, on my opinion this problem more related to mathematics rather then to programming. -
OMG :( this took me forever also my code is extensive.... looks like complying with DRY is going to take me looong time to master.
-
I solved !!
if (sum / 5 <= nickels && sum % 5 <= pennies){
return true;
}
else {
return false;
} -
At the end of my program I write << return boolean; >> but program say error:
variable bool might not have been initialized
return bool; -
I found my solution;
when I defined boolean bool I must give amount to it LIKE boolean bool = false; -
I solved it but some complicated:
boolean bool=false;
for (int i =0; i<=pennies; i=i+1){
if((sum - i)%5 == 0)
{ bool= true; break;}} return bool;
-
boolean statement worked for me
boolean bob = sum % 5 <=pennies;
return bob; -
boolean bob = sum%5<=pennies; return bob;
-
if(sum%5 > pennies) {return false;}
return nickels*5 + pennies >= sum; -
I archived many comments here with solutions. You can link to your solution (in your submissions) to share it, but you shouldn't paste the whole solution in here.
-
@mistermase nice. See also the featured answer
-
i'm confused i'm not familiar with nickel and pennies and cents -.- do they have relationships with each other ? like how many cents are there in pennies or in nickel ? :)
-
i'm really sorry :( we have different currency here in our country .... that's why i'm confused -.-
-
American Currency^ LOL
-
For those of you in different countries: Pennies are 1 cent, Nickles are 5 cents (each).
-
Added a note to main content on their value.
-
-
OK, but see the featured answers for a more concise answer.
-
I wrote my code in python. it's working if i run this in some other compiler but here it's not.
my code -
Boilerplate code for this challenge wasn't provided for Python, so you need to take in the input yourself from STDIN.
-
int nCount = sum / 5; if (nCount <= nickels) { return sum % 5 <= pennies; } else { return false; }
-
int a=sum/5;
int b=sum%5;
if(nickels>=a && pennies>=b){
return true;
}
return false; -
if ((sum%nickels) > pennies) return false; return true;
how the heck did this pass all the tests..
-
Thanks, that's actually an edge case that wasn't covered before. The last test case will now check that condition so that code no longer passes.
-
I did this way
if(nickels>=sum/5 && pennies>=sum%5)
{
return true;
}
else
{
return false;
} -
Here's some working boilerplate for Ruby:
n = gets.chomp.to_i
n.times do
input = gets.chomp.split(" ").map(&:to_i)
nickels = input[0]
pennies = input[1]
desired_sum = input[2]
print correct_change?(nickels, pennies, desired_sum), "\n"
end -
here goes my take!
if (sum % nickels <= pennies && ((nickels *5)+ pennies) >= sum){
return true;
}
else{
return false; -
Here is mine;
public static bool doStuff(int nickels, int pennies, int sum) { if (nickels >= sum / 5) { return pennies >= sum - sum / 5 * 5; } return false; }
-
I am stuck on this
Quick question - Can this exercise be done only with if statements?
Lang - Python
Appreciate the help
Thank you
-
function recipe(sum ,nickels, pennies) {
let nickel = 5 * nickels / 100
let penny = 1 * pennies / 100
let change = nickel + penny
if (penny <= 4 && change % sum === 0) {
return 'true'
} else if (penny > 4) {
return 'false'
} else {
return 'false'
}
};
Hongwen
Nov 3, 9:36 PMFor input set 5 3 19, we can get 19 using 3 pennies and 4 nickels. So it should be true there.