I am most likely the greenest greenhorn on this site. Currently in school for software development and finishing my first quarter. I'm working on a simple problem where I need to create a function that returns exact change (as the title says). For example, if my input is $1.18 the output should read 1 dollar, 1 dime, 1 nickel, 3 pennies. I don't want the answer as I do want to learn this on my own. I'm posting more for a nudge in the right direction. My code is posted below:
fun main(args: Array<String>) {
var changeDue = 1.18;
Money(changeDue);
}
fun Money(changeDue: Double){
var dollars = Math.floor(changeDue / 1.0);
var changeDue0 = changeDue - (dollars * 1.0);
var quarters = Math.floor(changeDue / 0.25);
var changeDue1 = changeDue - (quarters * 0.25);
var dimes = Math.floor(changeDue / 0.10);
var changeDue2 = changeDue - (dimes * 0.10);
var nickel = Math.floor(changeDue / 0.05);
var changeDue3 = changeDue - (nickel * 0.05);
var penny = changeDue;
return Unit;
}
If someone has already answered this in the past, I apologize for posting a second thread and wasting your time.