I have to create a program that accepts the number of tile as input from the keyboard, and returns the number of tiles to the main method. It has to accept the number of tiles and calculates the cost of each tiles. The method has to return the cost to the main method and prompt the user if he/she wants to purchase another item. I'm having trouble computing the subtotal, and how to keep a previous subtotal and add it to a new one they might be interested in... and further on down the line

Here's my code:

const int ART_STOP = 21;




            int intCount = 0;


        string inputString;
        decimal[] payRate = new decimal[] { 9.24m, 6.08m, 1.13m, 6.05m, 4.12m };
        string[] names = { "Ceramic", "Glass", "Metal", "Mosaic", "Stone" };
        bool isNameValid = false;
        int tileOrdered;
        string prefMaterial;
        decimal itemPrice = 0;
        int counter = 0;
        decimal subTotal;
        char response;
        decimal newTotal;




        for (int count = 0; count <= ART_STOP; ++count)//this for loop adds ascii to the program by setting the count to zero
        //and stops the art once it is greater than or equal to 20, and if not it adds one to it 
        {
            Write("<3");//adds ascii to the program to make it more presentable
        }
        WriteLine("");
        Write("   WELCOME TO KENNEDY'S HOUSE OF TILES!!!"   ); WriteLine("");

        for (int count = 0; count <= ART_STOP; ++count)//this for loop adds ascii to the program by setting the count to zero
        //and stops the art once it is greater than or equal to 20, and if not it adds one to it 
        {
            Write("<3");//adds ascii to the program to make it more presentable
        }
        WriteLine("");
        WriteLine("");

        Write("Each tile purchased holds a value of $7 each."); WriteLine("");

        Write("Enter the amount of tile blocks you would like to purchase: ");
        inputString = ReadLine();
        tileOrdered = Convert.ToInt32(inputString);

        Write("Here is your list of tiles to choose from: "); WriteLine("");
        WriteLine("");

        WriteLine("-------------------");
        WriteLine("Texture   |   Price");
        WriteLine("-------------------");


        for (intCount = 0; intCount < names.Length; ++intCount)
        {
            WriteLine("{0, 9} | {1}", names[intCount], payRate[intCount]);
        }

        WriteLine("");
        Write("Enter the tile material you would like to purchase: ");
        prefMaterial = ReadLine();

        while (counter < names.Length && prefMaterial != names[counter])
        {
            counter++;
        }
        if (counter != names.Length)
        {
            isNameValid = true;
            itemPrice = payRate[counter]; 
        }

        if (isNameValid)
        {
            Write("You have chosen the following: ");
            ItemPreferred(prefMaterial, itemPrice);
        }
        else
        {
            WriteLine("Please enter a valid material ");
        }

        subTotal = DisplaySubTotal(tileOrdered, itemPrice);
        WriteLine("Your Subtotal Is: {0}", subTotal.ToString("C"));

        Write("Do you want to select another tile to add? Y or N: ");
        inputString = ReadLine();
        response = Convert.ToChar(inputString);
        while (response == 'Y')
        {
            Write("Each tile purchased holds a value of $7 each."); WriteLine("");

        Write("Enter the amount of tile blocks you would like to purchase: ");
        inputString = ReadLine();
        tileOrdered = Convert.ToInt32(inputString);

        Write("Here is your list of tiles to choose from: "); WriteLine("");
        WriteLine("");

        WriteLine("-------------------");
        WriteLine("Texture   |   Price");
        WriteLine("-------------------");


        for (intCount = 0; intCount < names.Length; ++intCount)
        {
            WriteLine("{0, 9} | {1}", names[intCount], payRate[intCount]);
        }
            while (counter < names.Length && prefMaterial != names[counter])
            {
                counter++;
            }
            if (counter != names.Length)
            {
                isNameValid = true;
                itemPrice = payRate[counter];
            }
            Write("Enter the tile material you would like to purchase: ");
            prefMaterial = ReadLine();

            while (counter < names.Length && prefMaterial != names[counter])
            {
                counter++;
            }
            if (counter != names.Length)
            {
                isNameValid = true;
                itemPrice = payRate[counter];
            }

            if (isNameValid)
            {
                Write("You have chosen the following: ");
                ItemPreferred(prefMaterial, itemPrice);
            }
            else
            {
                WriteLine("Please enter a valid material ");
            }

            newTotal = subTotal + 
            WriteLine("Your Subtotal Is: {0}", newTotal.ToString("C"));
     (HERE IS WHAT I DO NOT UNDERSTAND, GETTING THE PREVIOUS TOTAL AND ADDING IT TO THE NEW ONE)


            Write("Do you want to select another tile to add ? Y or N:");
            inputString = ReadLine();
            response = Convert.ToChar(inputString);


        }
        WriteLine("Enjoy Your Day!!");

        Read();

    }
    private static void ItemPreferred(string names, decimal rate)
    {
        WriteLine("");
        WriteLine("-------------------");
        WriteLine("Texture   |   Price");
        WriteLine("-------------------"); WriteLine("");
        WriteLine("{0}     |    {1}", names, rate);
        WriteLine("-------------------"); WriteLine("");
        WriteLine("*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!*!");



    }

    private static decimal DisplaySubTotal(int tile, decimal payRate)
    {
        decimal sub;
        const int RATE = 7;
        sub = tile * RATE + payRate;
        return sub;

    }

    }
}

Recommended Answers

All 2 Replies

The code pasted is too much. What is the issue, paste the part with the issue.

newTotal = subTotal + 
        WriteLine("Your Subtotal Is: {0}", newTotal.ToString("C"));
        Im having trouble with forming an equation for my newTotal. It has to be equal to the subtotal from the previous input as well as any other tiles they would like to buy. I cant seem to figure out how to go about pulling a subtotal and having it add the users input each time 
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.