Thread: C# compute program

  1. #1
    Registered User
    Join Date
    Jan 2009

    C# compute program


    I have written this new code but it is not working and i am not able to debug the program as there is some syntax error. As I am new to C# programming I am not sure where I am going wrong
        class Program
            static void Main(string[] args)
                String response;
                Double labor = 0, cost = 0, lc, pc, tc, total = 0;
                int count = 0;
                    Console.WriteLine("Please Enter the Customer Name or quit to end: ");
                    response = Console.ReadLine();
                    if (response != "quit")
                        Console.WriteLine("Please Enter hours of labor: ");
                        labor = Console.Read();
                        Console.WriteLine("Please Enter cost of parts: ");
                        cost = Console.Read();
                        lc = labor * 35;
                        pc = cost + 0.5;
                        tc = lc + pc;
                        total = total + tc;
                        Console.WriteLine("Customer  :   " + response);
                        Console.WriteLine("Labor Cost:   " + lc);
                        Console.WriteLine("Parts Cost:   " + pc);
                        count = count + 1;
                    Console.Write("The total cost is {0:c} ", total);
                    Console.Write(" for " + count + " customers.");
                } while (response != "quit");
    the output that I am giving is

    if I enter a cust name it will run the 'if' loop and if I type quit then it will just show the total and end the loop....

    And I am not able to get any output of any sort there is no error in the code but it is not working
    Last edited by shady_shockerz; 02-10-2009 at 06:10 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    And what is the difference between what you are seeing and what you expect to see?

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Join Date
    Dec 2007
    Try this:
     Console.WriteLine("Please Enter hours of labor: ");
    labor = Convert.ToDouble(Console.ReadLine());
    Console.WriteLine("Please Enter cost of parts: ");
    cost = Convert.ToDouble(Console.ReadLine());
    but be aware if the user enters something non-numeric, it will crash. A better choice would be to use Double.TryParse(), but I'm not sure if that's something you've been taught yet.

    Also, change Console.Write() at the end -- which doesn't compile -- to Console.WriteLine()

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM