Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.60/5 (3 votes)
See more:
Hello, This Program i'm using, although it will compile, it won't continue after the first module, it automatically stops after the 1st 4 steps. The main module won't call to modules (computeTotal) or (computeTax) thus halting debug. Any idea whats going on? need finish this in the next 2 hours.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication19
{
    class Program
    {
        public static void Main()
        {
            string name = "";
            int itemQuantity = 0;
            double itemPrice = 0.0;
            string state = "";
            double total = 0.0;

            name = PromptAndInput("Enter the name of the customer: ");
            state = PromptAndInput("In which state (NY / NJ / FL) ? ");

            if (state != "NJ" & state != "nj" & state != "NY" & state != "ny" & state != "FL" & state != "fl")
            {
                Console.WriteLine("Error");
                while (state != "NJ" & state != "nj" & state != "NY" & state != "ny" & state != "FL" & state != "fl")
                {
                    state = PromptAndInput("In which state (NY / NJ / FL) ? ");
                }
            }

            itemQuantity = int.Parse(PromptAndInput("How many items were purchased?: "));
            if (itemQuantity < 0)
            Console.WriteLine("Error");
            while (itemQuantity < 0)
            itemQuantity = int.Parse(PromptAndInput("How many items were purchased?: "));

            itemPrice = double.Parse(PromptAndInput("What was the unit price of the items?: "));
            if (itemPrice < 0)
            Console.WriteLine("Error");
            while (itemPrice < 0)
            itemPrice = double.Parse(PromptAndInput("What was the unit price of the items?: "));

            computeTotal(itemQuantity, itemPrice, total, name);
            computeTax(state, total, itemQuantity, itemPrice);
        }

        public static string PromptAndInput(string prompt)
        {
            string userInput;
            Console.Write(prompt);
            userInput = Console.ReadLine();
            return userInput; 
        }

        public static object computeTotal(int itemQuantity, double itemPrice, double total, string name)
        {
            total = itemQuantity * itemPrice;
            Console.WriteLine();
            Console.WriteLine("--------------------------------------------------");
            Console.WriteLine("The total sales for " + name + " are: " + total);
            return total;
        }

        public static object computeTax(string state, double total, int itemQuantity, double itemPrice)
        {
            double taxAmt = 0.0;
            double totalSales = 0.0;
            double tax = 0.0;

            total = itemQuantity * itemPrice;

            if (state == "NJ" | state == "nj")
            {
                tax = 0.07;
            }
            else if (state == "NY" | state == "ny")
            {
                tax = 0.04;
            }
            else if (state == "FL" | state == "fl")
            {
                tax = 0.06;
            }

            taxAmt = total * tax;
            totalSales = total + taxAmt;

            Console.WriteLine("The tax amount is " + taxAmt + " based on a tax rate of: " + tax);
            Console.WriteLine("The total with taxes is: " + totalSales);
            Console.WriteLine("--------------------------------------------------");
            return totalSales;
        }
    }
}
Posted
Updated 26-Apr-15 21:08pm
v2
Comments
Sergey Alexandrovich Kryukov 27-Apr-15 0:14am    
What do you call "module" here?
—SA
Member 11644125 27-Apr-15 0:40am    
Public Static Object ComputeTax
and
Public Static Object ComputeTotal
(Our prof. called them modules, they may be referred as something else)

All i know is during the program debug, after answering :What is the unit price of the item

the program concludes

instead of calling on either of those two modules, which are to calculate from the given information from the main module. and then display the information after the calculations are finished
Sinisa Hajnal 27-Apr-15 2:51am    
I'm guessing you're inputing wrong decimal separator. Try changing 22,85 to 22.85 or vice versa. Better yet, put TRY..CATCH around the code and print out the exception - you'll get exactly what's wrong with the code.

"Modules" are commonly known as methods or functions. Only VB has "modules", generally collection of methods accessible only within the project.
Richard MacCutchan 27-Apr-15 3:47am    
You should use the TryParse method (not module), which will alert you if the value returned is invalid. See https://msdn.microsoft.com/en-us/library/f02979c7%28v=vs.110%29.aspx for the integer sample, the version for Double is similar.

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