Question I just started learning C# and already I have a problem.


New member
Dec 6, 2018
Programming Experience
Hello folks. I am possibly the most inexperienced person right now in the forum when it comes to writing codes and understanding most of it. I have been reading a book and so far have made it through to operators.

What basically is the idea that I am trying to test myself by allowing the user to enter a random amount and I would like to program it in a way that the result, depending on the input value, shows the denominations of the amount. To make it simpler, say I have 1270 USD. This is the amount the user inputs. The program should then be able to identify and inform the user how many 10s or 20s or 50s or 100s the amount will be comprising making up to the total value entered by the user.

I just started typing the code (again, I am a starter and I have only a bleak idea). This is what I typed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Task_1
    class Program
        static void Main(string[] args)
            Console.Write("Your total amount: ");
            int amount = Console.Read();

            int Thousand = amount / 1000;
            Console.Write("1000 x ");

So i tested it. I entered 1200 as a test and it shows;

Your total amount: 1200
1000 x 0
Press any key to continue...

I am lost. Absolutely lost. I would request whosoever can help me out here, please explain it to me in the most basic way possible :) I really wish to enter the field and your assistance would do me great help.
You should start by reading the documentation for the Console.Read method to see what it does and whether that is what you actually want. Here's a hint: it's not. You should then see what other methods the Console class has and whether one of them is more appropriate.
Well, It seems that I was able to do it. Didn't realize it could be easier than I thought.

Here is the finalized code.

    class Program
        public static void Main()
            Console.Write("please enter the amount: ");
            int amount = Convert.ToInt32(Console.ReadLine());

            int thousand = amount / 1000;
            int remainder = amount % 1000;

            int fiveHundred = remainder / 500;
            int remainder2 = remainder % 500;

            int oneHundred = remainder2 / 100;
            int remainder3 = remainder2 % 100;

            int fifty = remainder3 / 50;
            int remainder4 = remainder3 % 50;

            int twenty = remainder4 / 20;
            int remainder5 = remainder4 % 20;

            int ten = remainder5 / 10;
            int remainder6 = remainder5 % 10;

            int five = remainder6 / 5;
            int remainder7 = remainder6 % 5;

            int two = remainder7 / 2;
            int remainder8 = remainder7 % 2;

            int one = remainder8 / 1;

            Console.WriteLine("1000 : "+ thousand);
            Console.WriteLine("500 : "+ fiveHundred);
            Console.WriteLine("100 : "+ oneHundred);
            Console.WriteLine("50 : "+ fifty);
            Console.WriteLine("20 : "+ twenty);
            Console.WriteLine("10 : "+ ten);
            Console.WriteLine("5 : "+ five);
            Console.WriteLine("2 : "+ two);
            Console.WriteLine("1 : "+ one);

That worked like a charm. Thanks for the assistance mate :)
Top Bottom