Results 1 to 3 of 3

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

  1. #1
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2018
    Posts
    2
    Rep Power
    0

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

    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();
    Console.WriteLine(amount);


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



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

    Your total amount: 1200
    49
    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.

  2. #2
    .NET Framework
    .NET 4.5
    Join Date
    Apr 2011
    Posts
    1,979
    Rep Power
    154
    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.

  3. #3
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2018
    Posts
    2
    Rep Power
    0
    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

Similar Threads

  1. Machine Learning
    By code_ai in forum C# General Discussion
    Replies: 0
    Last Post: 11-06-2018, 6:20 PM
  2. Question Doutbs on how to start learning c#
    By Richard in forum General Learning Resources Discussion
    Replies: 0
    Last Post: 05-14-2017, 6:34 PM
  3. Question Learning Window Applications..
    By nydevil in forum Windows Forms
    Replies: 1
    Last Post: 03-03-2016, 6:38 PM
  4. getting started with XML
    By Rhodan in forum XML
    Replies: 1
    Last Post: 04-09-2015, 11:50 AM
  5. Question Sip webphone in How to get started?
    By theophil1901 in forum Third Party Products
    Replies: 0
    Last Post: 02-19-2015, 10:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •