Click here to Skip to main content
15,391,989 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, I'm making a simple program for school. I thought I had done it correctly, but when I go to run it, it doesn't output anything after "Your change is ".

namespace Lab7
{
    class Program
    {
        static void Main(string[] args)
        {
            Problem1();
            //Problem2();
            //Problem3();
            //Problem4();
            //Problem5();
            //Problem6();
            //Problem7();
            //Problem8();
            //Problem9();
            //Problem10();

            Console.ReadKey();
        }
        static void Problem1()
        {
            int quarter = 25;
            int numQuarters = 0;
            int dime = 10;
            int numDimes = 0;
            int nickel = 5;
            int numNickels = 0;
            int penny = 1;
            int change;
            
            Console.WriteLine("Enter total change: ");
            change = Convert.ToInt32(Console.ReadLine());

            if (change % quarter == 0)
            { Console.WriteLine("Your change is ", change / quarter, "quarters."); }
            else numQuarters = change / quarter; change = change % quarter;
            if (change % dime == 0)
            { Console.WriteLine("Your change is ", numQuarters, "quarters and ", change / dime, "dimes."); }
            else numDimes = change / dime; change = change % dime;
            if (change % nickel == 0)
            { Console.WriteLine("Your change is ", numQuarters, "quarters, ", numDimes, "dimes, and ", change / nickel, "nickels.");}
            else numNickels = change / nickel; change = change % nickel;
            if (change % penny == 0)
            { Console.WriteLine("Your change is ", numQuarters, "quarters, ", numDimes, "dimes, ", numNickels, "nickels, and ", change / penny, "pennies."); }





        }
        //static void Problem2(string[] args)
        //{

        //}
        //static void Problem3(string[] args)
        //{

        //}
        //static void Problem4(string[] args)
        //{

        //}
        //static void Problem5(string[] args)
        //{

        //}
        //static void Problem6(string[] args)
        //{

        //}
        //static void Problem7(string[] args)
        //{

        //}
        //static void Problem8(string[] args)
        //{

        //}
        //static void Problem9(string[] args)
        //{

        //}
        //static void Problem10(string[] args)
        //{

        //}

    }

}


What I have tried:

This is my first time writing C# code, so I'm totally lost. We just finished with Python.
Posted
Updated 21-Nov-21 23:41pm

Strings are not handled exactly the same way in C# and python.
Here you will find how to use Console.WriteLine Method (System) | Microsoft Docs[^]
e.g.
C#
Console.WriteLine("Your change is {0} quarters.", change / quarter);
   
Comments
Maciej Los 22-Nov-21 5:41am
   
5ed!
@phil.o is right.
Another way is to use below format:
C#
Console.WriteLine($"Your change is {change / quarter} quarters.");

For further information, please see: $ - string interpolation - C# reference | Microsoft Docs[^]
   
Comments
phil.o 22-Nov-21 6:19am
   
Hi Maciej, good point :)
Maciej Los 22-Nov-21 7:05am
   
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900