Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Need help. Hit learning barrier. [modified]

Need help. Hit learning barrier. [modified]

Scheduled Pinned Locked Moved C#
csharplearninghelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JMOdom
    wrote on last edited by
    #1

    :^) I am trying to learn C# in a classroom setting. I have hit a barrier in trying to understand something. In the following code sample under where it says weeklySalesAmount I get the message "The name 'weeklySalesAmount' does not exist in the current context". And under the mutators section where it says SetGrossPay it tells me "'Exercise_9_Chapter_4.Deduction.SetGrossPay(double)': not all code paths return a value" public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; } //MUTATORS: public double SetGrossPay(double weeklySales) { const double GROSS_WEEKLY_PAY = .07; grossPay = weeklySales * GROSS_WEEKLY_PAY; } In the next section where it says .netPay I'm told that "'Exercise_9_Chapter_4.Deduction.netPay' is inaccessible due to its protection level",and that SetNetPay is "The name 'SetNetPay' does not exist in the current context". Deduction employee = new Deduction(empName, wkSales); employee.netPay = SetNetPay(); I thought that I had everything done correctly according to the book. I have no idea as how to correct these problems. If anyone can help me, or at least steer me in the right direction, it would be muchly appreciated. Thank you.:rose::confused::-O -- modified at 17:04 Monday 26th February, 2007

    C D 2 Replies Last reply
    0
    • J JMOdom

      :^) I am trying to learn C# in a classroom setting. I have hit a barrier in trying to understand something. In the following code sample under where it says weeklySalesAmount I get the message "The name 'weeklySalesAmount' does not exist in the current context". And under the mutators section where it says SetGrossPay it tells me "'Exercise_9_Chapter_4.Deduction.SetGrossPay(double)': not all code paths return a value" public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; } //MUTATORS: public double SetGrossPay(double weeklySales) { const double GROSS_WEEKLY_PAY = .07; grossPay = weeklySales * GROSS_WEEKLY_PAY; } In the next section where it says .netPay I'm told that "'Exercise_9_Chapter_4.Deduction.netPay' is inaccessible due to its protection level",and that SetNetPay is "The name 'SetNetPay' does not exist in the current context". Deduction employee = new Deduction(empName, wkSales); employee.netPay = SetNetPay(); I thought that I had everything done correctly according to the book. I have no idea as how to correct these problems. If anyone can help me, or at least steer me in the right direction, it would be muchly appreciated. Thank you.:rose::confused::-O -- modified at 17:04 Monday 26th February, 2007

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Don't post programming questions in the lounge. I moved it for you.

      JMOdom wrote:

      "'Exercise_9_Chapter_4.Deduction.SetGrossPay(double)': not all code paths return a value"

      In fact, none of them return a value. That's what the message is telling you. You wrote a function that returns double, and you didn't return anything. Add return grossPage; at the end of the function and it will work. Also, if you have const values, it's a good idea to put them at the top, the whole point is that you can easily change them. Putting them in the function, you may as well hard code the value.

      JMOdom wrote:

      'Exercise_9_Chapter_4.Deduction.netPay' is inaccessible due to its protection level",

      This means that netPay is private or protected. You should use public properties to expose private or protected members. You should expose only a get method if at all possible. Oh - if you didn't put an access modifier, it's private by default. What I mean is: int n; is private. public int n; is public, but you should instead do this: private int _n; public int N { { get { return _n; } // set { _n = value; } } and only uncomment/add the set if you have to.

      JMOdom wrote:

      and that SetNetPay is "The name 'SetNetPay' does not exist in the current context".

      You've not shown us any code which involves a method called SetNetPay, so I can only assume this error is correct ( the method does not exist )

      JMOdom wrote:

      I have no idea as how to correct these problems

      I'm happy to help, but in each case, the compiler has told you what is wrong. As I help you through these issues, take note of what the terminology is, so you can learn how to use the error messages to work out how to fix your code :-)

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • J JMOdom

        :^) I am trying to learn C# in a classroom setting. I have hit a barrier in trying to understand something. In the following code sample under where it says weeklySalesAmount I get the message "The name 'weeklySalesAmount' does not exist in the current context". And under the mutators section where it says SetGrossPay it tells me "'Exercise_9_Chapter_4.Deduction.SetGrossPay(double)': not all code paths return a value" public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; } //MUTATORS: public double SetGrossPay(double weeklySales) { const double GROSS_WEEKLY_PAY = .07; grossPay = weeklySales * GROSS_WEEKLY_PAY; } In the next section where it says .netPay I'm told that "'Exercise_9_Chapter_4.Deduction.netPay' is inaccessible due to its protection level",and that SetNetPay is "The name 'SetNetPay' does not exist in the current context". Deduction employee = new Deduction(empName, wkSales); employee.netPay = SetNetPay(); I thought that I had everything done correctly according to the book. I have no idea as how to correct these problems. If anyone can help me, or at least steer me in the right direction, it would be muchly appreciated. Thank you.:rose::confused::-O -- modified at 17:04 Monday 26th February, 2007

        D Offline
        D Offline
        DavidNohejl
        wrote on last edited by
        #3

        JMOdom wrote:

        "The name 'weeklySalesAmount' does not exist in the current context"

        JMOdom wrote:

        public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; }

        You need to declare variable "weeklySalesAmount". Probably at same place as variable "name".

        JMOdom wrote:

        'Exercise_9_Chapter_4.Deduction.SetGrossPay(double)': not all code paths return a value"

        JMOdom wrote:

        public double SetGrossPay(double weeklySales) { const double GROSS_WEEKLY_PAY = .07; grossPay = weeklySales * GROSS_WEEKLY_PAY; }

        And that is correct, SetGrossPay has return type of double, you should have return grossPay; before closing bracket. Or better, change return type from double to void. It sucks if examples in your book don't even compile. :doh: Not that surprising tho.


        "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus

        J 1 Reply Last reply
        0
        • D DavidNohejl

          JMOdom wrote:

          "The name 'weeklySalesAmount' does not exist in the current context"

          JMOdom wrote:

          public Deduction(string empName, double weeklySales) { name = empName; weeklySalesAmount = weeklySales; }

          You need to declare variable "weeklySalesAmount". Probably at same place as variable "name".

          JMOdom wrote:

          'Exercise_9_Chapter_4.Deduction.SetGrossPay(double)': not all code paths return a value"

          JMOdom wrote:

          public double SetGrossPay(double weeklySales) { const double GROSS_WEEKLY_PAY = .07; grossPay = weeklySales * GROSS_WEEKLY_PAY; }

          And that is correct, SetGrossPay has return type of double, you should have return grossPay; before closing bracket. Or better, change return type from double to void. It sucks if examples in your book don't even compile. :doh: Not that surprising tho.


          "Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus

          J Offline
          J Offline
          JMOdom
          wrote on last edited by
          #4

          :)Thanks for the answers folks. Sorry I got into the area. All I can say is that I'm very new at this. The answers given have helped greatly. Thanks again.:rose::cool:

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups