Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi everyone! I am currently in a C# class and I\'m barely starting to get the ha

ID: 3858343 • Letter: H

Question

Hi everyone!

I am currently in a C# class and I'm barely starting to get the hang of it agai. The instructor gave us this question,

A customer hands you a one hundred dollar bill for a purchase. Enter a purchase from 1 cent to $99.99 and have the computer give you proper change, using the minimum amount of bills and or coins.

I know it might be an easy question but I am having some trouble.

I have to do this on visual studio and present it in a windows forms app, and I just can't seem to wrap my head around it.

If anyone could just help me out with an explanation that would be great.

Explanation / Answer

The code for the changing of the bill into small currency is as follows:

CurrencyChanger.cs

public string[] getChanges(double gvChnge)

{

double dueChng = gvChnge - tot();

string curr = dueChng.ToString();

int doll = Int32.Parse(curr.Split('.')[0]);

int cnt = Int32.Parse(curr.Split('.')[1]);

string formatChanges = "";

if ((doll / 50) != 0)

{

formatChanges += doll / 50 + " Fifty(s)" + Environment.NewLine;

doll %= 50;

}

if ((doll / 20) != 0)

{

formatChanges += doll / 20 + " Twenty(s)" + Environment.NewLine;

doll %= 20;

}

if ((doll / 10) != 0)

{

formatChanges += doll / 10 + " Ten(s)" + Environment.NewLine;

doll %= 10;

}

if ((doll / 5) != 0)

{

formatChanges += doll / 5 + " Five(s)" + Environment.NewLine;

doll %= 5;

}

if (doll != 0) formatChanges += doll + " One(s)" + Environment.NewLine;

if ((cnt / 25) != 0)

{

formatChanges += cnt / 25 + " Quarter(s)" + Environment.NewLine;

cnt %= 25;

}

if ((cnt / 10) != 0)

{

formatChanges += cnt / 10 + " Dime(s)" + Environment.NewLine;

cnt %= 10;

}

if ((cnt / 5) != 0)

{

formatChanges += cnt / 5 + " Nickels" + Environment.NewLine;

cnt %= 5;

}

if (cnt != 0) formatChanges += cnt + " Penny(s)";

return new string[] { dueChng.ToString(), formatChanges };

}

Please rate the answer if it helped......Thankyou

Hope it helps....

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote