Getting errors stating that 'Assignment3.Converter' does not contain a definition for 'breakdown'...cannot get this to work...I know there is a problem with the breakdown and dollarAmount, but I can't seem to figure out the solution.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Assignment3
{
    class Converter
    {
        private int currency;

        public static void converter(int currency, int[] breakdown, int[] demon)
        {
         
            int diff = currency;
            int x = 0;
            while (diff > 0)
            {
                breakdown[x] = diff / (demon[x]);
                diff = diff % demon[x];
                x++;
            }
        }
    }
        class Conversion
        {
            static void Main(string[] args)
            {
                int[] breakdown = new int[4];
                int[] demon = { 20, 10, 5, 1 };
                Converter converter = new Converter();
                Converter.converter(dollarAmount, breakdown, demon);
                Console.Write("Please enter a dollar amount: ");//prompts the user for an integer number of dollars
                Converter.dollarAmount = Convert.ToInt32(Console.ReadLine());    
                Console.WriteLine("The amount entered was: {0:c}", Converter.dollarAmount);
                Console.WriteLine("Twentys: {0}", Converter.breakdown[0]);
                Console.WriteLine("Tens: {1}", Converter.breakdown[1]);
                Console.WriteLine("Fives: {2}", Converter.breakdown[2]);
                Console.WriteLine("Ones: {3}", Converter.breakdown[3]);

            }
        }
}

Recommended Answers

All 2 Replies

Here is your code reposted, with [code] [/code] tags so we can actually read it:

namespace Assignment3 {
    class Converter {
        private int currency;

        public static void converter(int currency, int[] breakdown, int[] demon) {

            int diff = currency;
            int x = 0;
            while (diff > 0) {
                breakdown[x] = diff / (demon[x]);
                diff = diff % demon[x];
                x++;
            }
        }
    }
    class Conversion {
        static void Main(string[] args) {
            int[] breakdown = new int[4];
            int[] demon = { 20, 10, 5, 1 };
            Converter converter = new Converter();
            Converter.converter(dollarAmount, breakdown, demon);
            Console.Write("Please enter a dollar amount: ");//prompts the user for an integer number of dollars
            Converter.dollarAmount = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("The amount entered was: {0:c}", Converter.dollarAmount);
            Console.WriteLine("Twentys: {0}", Converter.breakdown[0]);
            Console.WriteLine("Tens: {1}", Converter.breakdown[1]);
            Console.WriteLine("Fives: {2}", Converter.breakdown[2]);
            Console.WriteLine("Ones: {3}", Converter.breakdown[3]);

        }
    }
}

In line 21 you use a variable 'dollarAmount' which is never declared anywhere.
In lines 28,29 you try to reference a static variable in the Converter class 'dollarAmount'. There are no static variables in the Converter class.
In lines 30-33 you try to reference a static variable in the Converter class 'breakdown'. There still are no static variable in the Converter class.

You need to declare dollarAmount, and rethink what you are trying to access and where it actually resides (Hint: Why did you declare 'breakdown' in the Main method but not use it?)

Thanks for your help! I figured it out!!

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.