C# compute program

This is a discussion on C# compute program within the C# Programming forums, part of the General Programming Boards category; Hi, I have written this new code but it is not working and i am not able to debug the ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    11

    C# compute program

    Hi,

    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
    Code:
    {
        class Program
        {
            static void Main(string[] args)
            {
                String response;
                Double labor = 0, cost = 0, lc, pc, tc, total = 0;
                int count = 0;
                do
                {
                    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);
                        Console.WriteLine();
                        count = count + 1;
                    }
                    Console.Write("The total cost is {0:c} ", total);
                    Console.Write(" for " + count + " customers.");
                    Console.Write();
                } 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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    And what is the difference between what you are seeing and what you expect to see?

    --
    Mats
    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Try this:
    Code:
     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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21