1 dollars =100cent
Solution 1: Calculate in Main Method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | class Program { static void Main(string[] args) { double dollar_amount; int cents; // int compute_cents; Console.Write("Enter dollar amount :"); dollar_amount = Convert.ToDouble(Console.ReadLine()); cents =(int) (dollar_amount * 100); Console.WriteLine("{0} $ = {1} ¢",dollar_amount,cents); Console.ReadLine(); } } |
Solution 2: Calculate with Custom Method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | class Program { static void Main(string[] args) { double dollar_amount; int cents; // int compute_cents; Console.Write("Enter dollar amount :"); dollar_amount = Convert.ToDouble(Console.ReadLine()); cents = compute_cents(dollar_amount); Console.WriteLine("{0} $ = {1} ¢",dollar_amount,cents); Console.ReadLine(); } static int compute_cents(double dollar_amount) { return (int)(dollar_amount * 100); } } |
output: