Having problems with schoolwork. In C# within Console Application
The task is to enter the price and the cost of change back.
And that it should be visible which change you want, 20, 50, or 100 notes.
For example
Price 240;
Pay 95
Switch 140; your exchange
1 100 laps
2 twenty notes
Thinking about whether to do an if stasis
Kind of like this
Anyone who knows??-.
int price;
int pay;
int hundred = 100;
int fifty = 50;
int two hundred = 200;
int twenty = 20;
Console.WriteLine("Enter Price");
price = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" paid?");
pay = Convert.ToInt32(Console.ReadLine());
int amount = price - pay;
Console.WriteLine(" your gear back is " + sum);
Aravind GovindarajPosted Oct 19, 2022, 2:08 PM
Hi Mat,
Please follow the steps, once you received the remaining amount (int remaining amount = price - pay;)
1. Make it the nearest low round of value, in the above example, the amount is 145, make it 140 with the help of the nearest rounding-off value.
2. Create a class as Deomoniation
class Deomoniation
{
Number int;
Count int;
}
Set the denomination in Deomoniations as List
3. Loop this denomination
for each ( var denomination in denominations)
{
//Logic
//if denomination is greater than remaining amount the continue if not continue the below check
// 1st loop => 200 > 140 so continue nothing to do
// 2nd loop => 100 yes do the below one
// remainingamount mod deomoniation value ==0, then count it and subtract that value
// 140/100 yes => count denomination 100 as 1 then remaining balance 140 - 100 = 40
// 3rd loop => 50 > 40 nothing to do
// 4th loop => 40%20 == 0 then 40/20 =2 , denomination 20 count as 2 , remianig balance is 40-40=0
// 5th loop => 10>0 nothing to do
}
here if you se the deonomiration now
200 0
100 1
50 0
20 2
10 0
you can display the above one for domination count
Hope this helps you