Question make the solution more pretty?

papayagirl

New member
Joined
Feb 27, 2017
Messages
1
Programming Experience
Beginner
Hello!

I am very new to C#. Just attended one lesson so far.

It might be the most interesting thing I ever encountered and I am motivated to improve.

I just got completed an assignment which I am sure is not the most slick solution and I wonder if I could get some pointers on how to make the solution more pretty/efficient/non-noob? :)

The assignment was to write a simple program that exchange money to the biggest bills possible:

A. Let the user input the amount that he or she want to exchange.

B. Let the user know how many 500-bills, 100-bills and single coins that will be returned.

C. Write this on the screen.


I came up with this:

C#:
namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Input the amount you want to exchange: ");
            int amount = int.Parse(Console.ReadLine());


            int fivehundred = amount / 500;


            int leftHundredCoins = amount - (fivehundred * 500);


            int leftHundred = leftHundredCoins / 100;


            int fivehundredCoins = fivehundred * 500;


            int hundredCoins = leftHundred * 100;


            int billCoins = fivehundredCoins + hundredCoins;


            int leftCoins = amount - billCoins;




            Console.WriteLine("You will receive " + fivehundred + " 500-bills" + ", " + leftHundred + " 100-bills and " + leftCoins + " coins.");
            Console.ReadLine();
        }
    }
}

Appreciate all input. Sorry for the broken english, but it is not as broken as my C#
 

Latest posts

Back
Top Bottom