Requirements are listed throughout. I have tried with and without the converter. prefix.
Please help.

namespace Assignment_4b_Moon_money
{
    //program that contains a method that calculates the conversion of any amount of money into the fewest bills; it calculates
    //the number of 20s, 10s, 5s, and 1s needed.  This assignment includes the following requirements:

    /*  Create a converter class that will have a private integer currency variable and a public class 
    * implementation of the conversion method you created for Assignment_4a.
    */
     
    class Converter
    {
        //classs variable
       private int currency
      

        //class method
        //A conversion method that will have the arrays passed to it and that will perform the breakdown.
        public static void converter(int currency, int[] breakdown, int[] denom)
        {

            int diff = currency;
            int x = 0;

            while (diff > 0)
            {
                breakdown[x] = diff / (denom[x]);
                diff = diff % denom[x];
                x++;
            }

        } //end converter method

    }  // end Converter class

    class Conversion
    {
        static void Main(string[] args)
        {

            // In Main() instantiate a new converter object.
            Converter converter = new Converter();
            converter.converter(dollarAmount, breakdown, denom);
            
            //In Main() console code that prompts the user for an integer number of dollars.
           
            Console.Write("Please enter an amount: ");
            converter.dollarAmount = Convert.ToInt32(Console.ReadLine());

            //In Main() an integer array to hold the breakdown of each of the four amounts (20s, 10s, 5s and 1s).
            int[] breakdown = new int[4];

            //In Main() an integer array to hold the denominations that constitute the breakdown (20s, 10s, 5s and 1s).
            int[] denom = { 20, 10, 5, 1 };

            

            //Code in main that will display to the console the breakdown amounts.
            Console.WriteLine("The amount entered was: {0:c}", converter.dollarAmount);

            Console.WriteLine("Twentys: {0}", converter.breakdown[0]);
            Console.WriteLine("Tens: {0}", converter.breakdown[1]);
            Console.WriteLine("Fives: {0}", converter.breakdown[2]);
            Console.WriteLine("Ones: {0}", converter.breakdown[3]);

           // Internal Documentation.

        } //end main

    }  //end class conversion (main wrapper)
    
} //end namespace

Recommended Answers

All 3 Replies

Remove the word 'static' from line 18.

I had actually tried that, since you gave me that advice on an earlier problem. I still have problems.

This problem is a two part, first part we did it all under one class. The second part is under two classes with an object instantiated to produce the exact same results as the first one. The first part required a static method. Then at the bottom of the instructions for part 2, it states "all other requirements must be met". So I don't know if the static has to stay. If it does, how can I get it to work. Also, even after I remove static, I still get 2 errors regarding denom and breakdown not being declared.

Thank you for your help!

OK, so I just realized my arrays were BELOW the method call. I moved the call to below the array declarations and now have zero errors. I will see if it runs properly.

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.