Write C# Program to count total number of notes in entered amount


Introduction

Write C# Program to count total number of notes in entered amount. I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. public class csharpExercise
  7. {
  8. static void Main(string[] args)
  9. {
  10.  
  11. int amount;
  12.  
  13. int note1, note2, note5, note10, note20, note50, note100, note500;
  14.  
  15. note1 = note2 = note5 = note10 = note20 = note50 = note100 = note500 = 0;
  16.  
  17. Console.WriteLine("Enter amount: ");
  18. amount = Convert.ToInt32(Console.ReadLine());
  19.  
  20. if (amount >= 500)
  21. {
  22. note500 = amount / 500;
  23. amount -= note500 * 500;
  24. }
  25. if (amount >= 100)
  26. {
  27. note100 = amount / 100;
  28. amount -= note100 * 100;
  29. }
  30. if (amount >= 50)
  31. {
  32. note50 = amount / 50;
  33. amount -= note50 * 50;
  34. }
  35. if (amount >= 20)
  36. {
  37. note20 = amount / 20;
  38. amount -= note20 * 20;
  39. }
  40. if (amount >= 10)
  41. {
  42. note10 = amount / 10;
  43. amount -= note10 * 10;
  44. }
  45. if (amount >= 5)
  46. {
  47. note5 = amount / 5;
  48. amount -= note5 * 5;
  49. }
  50. if (amount >= 2)
  51. {
  52. note2 = amount / 2;
  53. amount -= note2 * 2;
  54. }
  55. if (amount >= 1)
  56. {
  57. note1 = amount;
  58. }
  59.  
  60. Console.WriteLine("Total number of notes = \n");
  61. Console.WriteLine("500 = "+ note500);
  62. Console.WriteLine("100 = "+ note100);
  63. Console.WriteLine("50 = "+ note50);
  64. Console.WriteLine("20 = "+ note20);
  65. Console.WriteLine("10 = "+ note10);
  66. Console.WriteLine("5 = "+ note5);
  67. Console.WriteLine("2 = "+ note2);
  68. Console.WriteLine("1 = "+ note1);
  69.  
  70. Console.ReadLine();
  71. }
  72. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts