Advertisement
IvanITD

3 - Money Maker

Jan 17th, 2024
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | Source Code | 0 0
  1. namespace Money_Maker
  2. {
  3.     internal class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             Console.WriteLine("Welcome to Money Maker!");
  8.  
  9.             // In the first section we need to ask the user for the amount for wich we will convert and capture the value in a variable!
  10.             Console.WriteLine("Dear user! \nPlease input your amount, in order to be converted into coins!");
  11.             string theAmount = Console.ReadLine();
  12.  
  13.             // Here we are going to convert the string variable into a double
  14.             double amount = Convert.ToDouble(theAmount);
  15.  
  16.             // In this particular section we need to inform the user about the inputted amount, from the beginning. The printed text should say: "'amount' cents is equal to...".
  17.             Console.WriteLine($"{amount} cents is equal to...");
  18.  
  19.             // Here we need to fine the value of each type of coin and then define two variables in wich we can put the values.
  20.             int goldValue = 10;
  21.             int silverValue = 5;
  22.  
  23.             // Now in order to find the maximum number of gold coins that can fit into the amount, we need to divide the amount by the value of the gold coins!
  24.             double goldCoins = Math.Round(goldValue / amount);
  25.             // Here we need to use the modulo in order to find the remaining amount and store it in a double variable!
  26.             double remainder = amount % goldValue;
  27.  
  28.             // Now we have to find the maximum amount of silver coins that fit into the remainder. In order to find that, we need to divide the remainder by the value of a silver coin!
  29.             double silverCoins = Math.Round(remainder / silverValue);
  30.  
  31.             // Here we need to find the remainder, in wich case the curent remainder are the "Bronze Coins"!
  32.             remainder = remainder % silverValue;
  33.  
  34.             // Now we need to print out all of the coins. We need to take every variable that we collected as information and print it together with the first printed amount!
  35.             Console.WriteLine($"Gold coins: {goldCoins}");
  36.             Console.WriteLine($"Silver coins: {silverCoins}");
  37.             Console.WriteLine($"Bronze coins: {remainder:F2}");
  38.         }
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement