5 Replies - 208 Views - Last Post: 10 September 2012 - 06:08 AM Rate Topic: -----

#1 newbie45  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-September 12

? on debugging

Posted 10 September 2012 - 02:12 AM

first lemme just say I'm new to C#...

I'm getting "the name Console does not exist in the current context"

--------- I know the rules.. not asking anyone to do my work... just point me in the correct direction.. please :)


 public class Commission {

    public static void main(String [] args) {

      Console.Write("Enter the amount of hardWare sales: ");      
      double hardWare = double.Parse(Console.ReadLine()); 

      Console.Write("Enter the amount of softWare sales: ");
      double softWare = double.Parse(Console.ReadLine());

      double amount = 0;

      if (hardWare < 40000.00)
         amount += .07 * hardWare;

      else
         amount = .1 * (hardWare - 40000.0);

      if (softWare < 20000.00)
         amount += .05 * softWare;

      else if (softWare > 20000.00 || softWare < 50000.00)
         amount += 1000  + .065 * (softWare - 50000.00);

      else
         amount = .075 * (softWare - 50000.00);

      Console.WriteLine("The commission is {0}",amount);

    }

  }

This post has been edited by Salem_c: 10 September 2012 - 02:22 AM
Reason for edit:: added [code][/code] tags - learn to use them yourself


Is This A Good Question/Topic? 0
  • +

Replies To: ? on debugging

#2 Mina-no-Hime  Icon User is offline

  • D.I.C Head

Reputation: 98
  • View blog
  • Posts: 176
  • Joined: 23-August 12

Re: ? on debugging

Posted 10 September 2012 - 02:24 AM

As a quick note, there are boards specifically dedicated to C# -- this is the C & C++ board.

The Console class exists in the System namespace, so you need to ensure you are using that. This can be done in one or two ways:

1) At the top of your file, include the following:
using System;


2) Call Console functions with their full name:
System.Console.WriteLine("何をしましたか");

Was This Post Helpful? 1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5672
  • View blog
  • Posts: 22,526
  • Joined: 23-August 08

Re: ? on debugging

Posted 10 September 2012 - 02:27 AM

Moved to C#
Was This Post Helpful? 0
  • +
  • -

#4 newbie45  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-September 12

Re: ? on debugging

Posted 10 September 2012 - 03:47 AM

thank you for input... I've made progress and am now able to compile and debug without errors... the output is incorrect, but I should be able to get this fixed now.
Was This Post Helpful? 0
  • +
  • -

#5 newbie45  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-September 12

Re: ? on debugging

Posted 10 September 2012 - 05:36 AM

next question.. I've made progress.. Now I have a question on my if-else statement and it not computing correctly.

the commission structure calls for the employee to receive 7% on sales up to 40k, and 10% on sales over the 40k. When I run the program and enter a sales amount of <40k it reads the statement and output is correct. However if I put in a sales amount greater than 40k, my program is applying the full 10% to the total sales, when what I want it to do is apply the 10% structure on the balance after subtracting the first 40k in sales that the salesperson is only getting 7% on...

if (hardWare < 40000.00)
amount += .07 * hardWare;

else
amount = .1 * (hardWare - 40000.0);
Was This Post Helpful? 0
  • +
  • -

#6 rgfirefly24  Icon User is offline

  • D.I.C Lover
  • member icon


Reputation: 233
  • View blog
  • Posts: 1,311
  • Joined: 07-April 08

Re: ? on debugging

Posted 10 September 2012 - 06:08 AM

Using an If Else like that makes it so that you will never calculate the 7% on sales between 0-40k if they made more then 40k in sales. Remember that an If statement is like a crossroads. You can go one way or the other, but not both.

you will want to do one of two things, Extract the calculations for Commission out into it's own method and recursively call it while hardWare is > 0, or change the if statement to also include the 7% calculation.

Also, I would Highly recommend the use of brackets even for single line statements.

You might want to look at your softWare if statement as well. on line 23 you say that if softWare is greater then 20k OR it is less then 50k then add .65*(softWare - 50000) to 1000. What if the software sales is 25000? then you are taking 1000 + .065*(25000 - 50000) or 1000 + .065*(-25000). That means that if i sell between 20k and 50k of software I could Owe the company money instead of making any. (The calculation for 25000 in sales is -625)

This post has been edited by rgfirefly24: 10 September 2012 - 06:15 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1