C
C#4mo 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
Jimmacle4mo ago
how would you do it if you were making change in real life?
mzxsu
mzxsu4mo ago
What do you mean this might sound stupid but id legit just use a calculator
oke
oke4mo 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
mzxsu4mo ago
could you convert this in AUD or is that dragged
oke
oke4mo ago
whats AUD
mzxsu
mzxsu4mo ago
australian dollar
oke
oke4mo ago
what exactly would you need to change...?
mzxsu
mzxsu4mo ago
i dont know this nickels dimes system actually i think i can do it other than taht thank you alot gah damn
oke
oke4mo 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
mzxsu4mo ago
goat also int oneDollars = 0; while (change >= 1) { change -= 1; oneDollars++; what excatly does this bit do?
oke
oke4mo 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
mzxsu4mo ago
ohhhhh i see thank you
oke
oke4mo ago
yw $close
MODiX
MODiX4mo ago
Use the /close command to mark a forum thread as answered
Yawnder
Yawnder4mo 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
oke4mo ago
he didnt close it and i just did it for simplicity's sake if you got something else, please share
Yawnder
Yawnder4mo ago
Yes, he did.
No description
oke
oke4mo ago
that was me, telling how how to close it
Yawnder
Yawnder4mo ago
Oh. Well I'm wrong! Sorry But before I'll elaborate on how, I'll see if they're still around.
oke
oke4mo 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
mzxsu3mo ago
oh i see ok got it $close
MODiX
MODiX3mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server
More Posts
IDE complaining that interface async methods are not implemented.```cs public interface INHibernateHelper { Task SetUsername(User user, string? username, ISessioAlternative to ReadLine for compiling to Zero Standard LibraryIm compiling to bare metal and need to use Readline, but the zero library doesnt have a definition freccomendations for learning how to work with streams.Im trying to dive deeper into how streams work in C# but i find it hard to jugde what source is a goguid doesn't change after postI defined my model ID's as guid to make it auto generated but after creating model. Is it about scop✅ Not sure why I'm getting this errorCode: https://pastebin.com/2u9HCy8U ```console CSC : error CS5001: Program does not contain a staticTarget multiple architectures at onceHey guys, I have an app I want to publish for linux-x64 and linux-arm64. I'm using the "RunTimeIdenHow to add additional headers/columns to CSV file?Using CSVHelper to manipulate a CSV file but when I try to add additional columns of information I gJWT refreshing + validatin/invalidating infinite error throwingHey, I have implemented a JWT refresh method (worked ast some point and then I tried adding invalida.NET 8 Simple Cookie AuthenticationHello, I am a bit confused about simple Cookie Authentication in .net 8 I have the following in my P✅ Hey, I am getting this error in VS code whenever I am trying to use a C# file.System.IO.FileNotFoundException: Retrieving the COM class factory for component with CLSID {177F0C4A