C
C#9mo ago
mzxsu

✅ Working on a change calculator, need help

So far this is what i got but i dont know what to do from here. these are the steps required Step 1: Prompt the user to enter the cost of the item Step 2: Prompt the user to enter the amount paid Step 3: Calculate the change Step 4: Determine the number of each type of coin needed for the change Step 5: Display the number of each type of coin to give as change its just step 4,5 im having trouble with, also if you notice any errors or anything i could fix let me know
No description
22 Replies
Jimmacle
Jimmacle9mo ago
how would you do it if you were making change in real life?
mzxsu
mzxsuOP9mo ago
What do you mean this might sound stupid but id legit just use a calculator
oke
oke9mo ago
you need to subtract the double by the highest currency value (starting from $1 [1.0], down to $0.01 [.01])
static void PrintExactChange(double change)
{
change = Math.Max(change, 0);

int dollars = (int)change;
change -= dollars;

int quarters = 0;
while (change >= 0.25)
{
change -= 0.25;
quarters++;
}

int dimes = 0;
while (change >= 0.10)
{
change -= 0.10;
dimes++;
}

int nickels = 0;
while (change >= 0.05)
{
change -= 0.05;
nickels++;
}

int pennies = (int)(change * 100);

Console.WriteLine($"Your change was {dollars} dollars, {quarters} quarters, {dimes} dimes, {nickels} nickels, and {pennies} pennies");
}
static void PrintExactChange(double change)
{
change = Math.Max(change, 0);

int dollars = (int)change;
change -= dollars;

int quarters = 0;
while (change >= 0.25)
{
change -= 0.25;
quarters++;
}

int dimes = 0;
while (change >= 0.10)
{
change -= 0.10;
dimes++;
}

int nickels = 0;
while (change >= 0.05)
{
change -= 0.05;
nickels++;
}

int pennies = (int)(change * 100);

Console.WriteLine($"Your change was {dollars} dollars, {quarters} quarters, {dimes} dimes, {nickels} nickels, and {pennies} pennies");
}
mzxsu
mzxsuOP9mo ago
could you convert this in AUD or is that dragged
oke
oke9mo ago
whats AUD
mzxsu
mzxsuOP9mo ago
australian dollar
oke
oke9mo ago
what exactly would you need to change...?
mzxsu
mzxsuOP9mo ago
i dont know this nickels dimes system actually i think i can do it other than taht thank you alot gah damn
oke
oke9mo ago
static void PrintExactChange(double change)
{
change = Math.Max(change, 0);

int dollars = (int)change;
change -= dollars;

int twoDollars = 0;
while (change >= 2)
{
change -= 2;
twoDollars++;
}

int oneDollars = 0;
while (change >= 1)
{
change -= 1;
oneDollars++;
}

int fiftyCents = 0;
while (change >= 0.50)
{
change -= 0.50;
fiftyCents++;
}

int twentyCents = 0;
while (change >= 0.20)
{
change -= 0.20;
twentyCents++;
}

int tenCents = 0;
while (change >= 0.10)
{
change -= 0.10;
tenCents++;
}

int fiveCents = (int)(change * 20);

Console.WriteLine($"Your change was {dollars} dollars, {twoDollars} two dollar coins, {oneDollars} one dollar coins, {fiftyCents} fifty cent coins, {twentyCents} twenty cent coins, {tenCents} ten cent coins, and {fiveCents} five cent coins, mate");
}
static void PrintExactChange(double change)
{
change = Math.Max(change, 0);

int dollars = (int)change;
change -= dollars;

int twoDollars = 0;
while (change >= 2)
{
change -= 2;
twoDollars++;
}

int oneDollars = 0;
while (change >= 1)
{
change -= 1;
oneDollars++;
}

int fiftyCents = 0;
while (change >= 0.50)
{
change -= 0.50;
fiftyCents++;
}

int twentyCents = 0;
while (change >= 0.20)
{
change -= 0.20;
twentyCents++;
}

int tenCents = 0;
while (change >= 0.10)
{
change -= 0.10;
tenCents++;
}

int fiveCents = (int)(change * 20);

Console.WriteLine($"Your change was {dollars} dollars, {twoDollars} two dollar coins, {oneDollars} one dollar coins, {fiftyCents} fifty cent coins, {twentyCents} twenty cent coins, {tenCents} ten cent coins, and {fiveCents} five cent coins, mate");
}
mzxsu
mzxsuOP9mo ago
goat also int oneDollars = 0; while (change >= 1) { change -= 1; oneDollars++; what excatly does this bit do?
oke
oke9mo ago
while the change amount is greater than or equal to 1.0, take $1 away from change and increment the dollar amount by one so: dollars = 0 change = 43.32 after one loop, it becomes: dollars = 1 change = 42.32 the same for all other amounts so: twentyCents = 0 change = 13.60 after one loop becomes: twentyCents = .20 change = 13.40
mzxsu
mzxsuOP9mo ago
ohhhhh i see thank you
oke
oke9mo ago
yw $close
MODiX
MODiX9mo ago
Use the /close command to mark a forum thread as answered
Yawnder
Yawnder9mo ago
@mzxsu I know you closed it, but I honestly wouldn't use any kind of loop for that if I were you. (And take that as a lesson of "Because something works doesn't mean it's the right solution.")
oke
oke9mo ago
he didnt close it and i just did it for simplicity's sake if you got something else, please share
Yawnder
Yawnder9mo ago
Yes, he did.
No description
oke
oke9mo ago
that was me, telling how how to close it
Yawnder
Yawnder9mo ago
Oh. Well I'm wrong! Sorry But before I'll elaborate on how, I'll see if they're still around.
oke
oke9mo ago
its okay any word starting with '$' is a command for info and you can tell if the thread is closed because the title will have a ✅ in front of it
mzxsu
mzxsuOP9mo ago
oh i see ok got it $close
MODiX
MODiX9mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server