using System; using static System.Console; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AMPCh02Ex04 { class Program { static void Main(string[] args) { int quarters, dimes, nickels, pennies, change = 15974; WriteLine("Change = " + $"{(double)change / 100:C}"); quarters = change / 25; change %= 25; dimes = change / 10; change %= 10; nickels = change / 5; change %= 5; pennies = change; WriteLine("Quarters = " + quarters); WriteLine("Dimes = " + dimes); WriteLine("Nickels = " + nickels); WriteLine("Pennies = " + pennies); ReadKey(); } } }

Respuesta :

I'll assume the question is "what is the output of the above program?"

Explanation:

First, I'll arrange the program in lines

using System;

using static System.Console;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace AMPCh02Ex04 {

class Program { static void Main(string[] args) {

int quarters, dimes, nickels, pennies, change = 15974;

WriteLine("Change = " + $"{(double)change / 100:C}");

quarters = change / 25;

change %= 25;

dimes = change / 10;

change %= 10;

nickels = change / 5;

change %= 5;

pennies = change;

WriteLine("Quarters = " + quarters);

WriteLine("Dimes = " + dimes);

WriteLine("Nickels = " + nickels);

WriteLine("Pennies = " + pennies);

ReadKey();

} } }

Explanation starts here

This line below declares integer variables. Variable changed is initialised to 15974

int quarters, dimes, nickels, pennies, change = 15974;

The line below divides 15974 as a double variable by 100 and displays the results as a currency.

WriteLine("Change = " + $"{(double)change / 100:C}");

The output is "Change = $15.974" without the quotes

quarters = change/25.

This divides 15974 by 25 and saves only the integer part to variable quarter. So

quarter = 638

change %= 25;

This calculates the remainder of 15974 divided by 25. The result is stored in variable change. So,

change = 24

dimes = change / 10;

This calculates the division of 24 by 10. The integer part of the result is stored in variable dimes. So,

dimes = 2

change %= 10;

This calculates the remainder of 24 divided by 10. The result is stored in variable change. So,

change = 4

nickels = change / 5;

This calculates the division of 4 by 5. The integer part of the result is stored in variable nickels. So,

nickels = 0

change %= 5;

This calculates the remainder of 4 divided by 5. The result is stored in variable change. So,

change = 4

pennies = change;

pennies = 4

WriteLine("Quarters = " + quarters);

"Quarters = 638" is printed without the quotes

WriteLine("Dimes = " + dimes);

"Dimes = 2" is printed without the quotes

WriteLine("Nickels = " + nickels);

"Nickels = 0" is printed without the quotes

WriteLine("Pennies = " + pennies);

"Pennies = 4" is printed without the quotes