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. can any one tell me whats wrong in this code?

can any one tell me whats wrong in this code?

Scheduled Pinned Locked Moved C#
question
11 Posts 9 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.
  • A Offline
    A Offline
    ademsandeepreddy
    wrote on last edited by
    #1

    using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

    hi

    K S L P C 7 Replies Last reply
    0
    • A ademsandeepreddy

      using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

      hi

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      What are you expecting it to do? What are you getting that you don't think you should? Are you getting some sort of error? Ben

      1 Reply Last reply
      0
      • A ademsandeepreddy

        using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

        hi

        S Offline
        S Offline
        Suj_78
        wrote on last edited by
        #3

        what error message are you getting? Did you declare the constructor in your class?

        happy coding!

        A 1 Reply Last reply
        0
        • A ademsandeepreddy

          using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

          hi

          L Offline
          L Offline
          Larantz
          wrote on last edited by
          #4

          Change this part of your code

          if (_acctype = "savings" || _acctype = "current")
          {
          _acctype = value;
          }
          else
          {
          _acctype = "";
          }

          to this

          if (_acctype == "savings" || _acctype == "current")
          {
          _acctype = value;
          }
          else
          {
          _acctype = "";
          }

          -Larantz-

          for those about to code, we salute you
          http://www.tellus-software.com

          1 Reply Last reply
          0
          • S Suj_78

            what error message are you getting? Did you declare the constructor in your class?

            happy coding!

            A Offline
            A Offline
            ademsandeepreddy
            wrote on last edited by
            #5

            iam getting identifier expected

            hi

            S L 2 Replies Last reply
            0
            • A ademsandeepreddy

              iam getting identifier expected

              hi

              S Offline
              S Offline
              Suj_78
              wrote on last edited by
              #6

              OK, Can you do the following: 1. Take out System.Collections for time being 2. Add the default constructor like public Bank(){}. 3. Comment out all your properties get and set methods. 4. Start building the code and start uncommenting each of the properties and then see what error message you get and at what stage , this will enable to to understand the problem better. Sorry cann't help more than this because don't have IDE in front of me, Hope you sort out your problem,

              happy coding!

              1 Reply Last reply
              0
              • A ademsandeepreddy

                using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

                hi

                P Offline
                P Offline
                PhilDanger
                wrote on last edited by
                #7

                Just as an aside --

                public int credit(_balance , _amount)
                {
                    return _balance + _amount;
                }
                public int debit(_balance , _amount)
                { 
                      return _balance - _amount;
                }
                

                These two functions have parameter names that hide the private members - so if you are trying to make the function use your actual balance instead of a balance that is passed in, they should be declared as: public int credit(_amount){/*code*/} and public int debit(_amount){/*code*/} And if you want the balance to actually be updated, you'll need to do _balance -= _amount; or _balance += _amount; (this is assuming that you actually do want it to be updated)

                1 Reply Last reply
                0
                • A ademsandeepreddy

                  using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

                  hi

                  C Offline
                  C Offline
                  Clinkz
                  wrote on last edited by
                  #8

                  You need to fix your acctype property public string acctype { get { return _acctype; } set { if (value == "savings" || value == "current") { _acctype = value; } else { _acctype = String.Empty; } } }

                  1 Reply Last reply
                  0
                  • A ademsandeepreddy

                    using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

                    hi

                    S Offline
                    S Offline
                    shrapnel_indie
                    wrote on last edited by
                    #9

                    Ok, after looking at your code, AND the other replies, there are areas that do have real problems. LOGICAL ERROR: public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } In your test, you are assigning the strings to _acctype, what you accomplish will not be what you want, as _acctype will always be assigned the contents of value. QUESTIONABLE on what you are attempting to do: public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } you are overriding the internal private class variables _balance and _amount with what you pass in as _balance and _amount. Im not sure what you intended to do here. Is the class variable _amount needed? Are you trying to update _balance, or are you just attempting to deliver the would be changes just for the values or to update externally? -Later! -WB-

                    1 Reply Last reply
                    0
                    • A ademsandeepreddy

                      using System; using System.Collections.Generic; using System.Text; namespace ClassLibrary1 { public class bank { private int _accno; private string _acctype; private int _balance; private int _amount; public int accno { get { return _accno; } set { _accno = value; } } public string acctype { get { return _acctype; } set { if (_acctype = "savings" || _acctype = "current") { _acctype = value; } else { _acctype = ""; } } } public int balance { get { return _balance; } } public int amount { get { return _amount; } set { _amount = value; } } public int credit(_balance , _amount) { return _balance + _amount; } public int debit(_balance , _amount) { return _balance - _amount; } } }

                      hi

                      A Offline
                      A Offline
                      aztekka
                      wrote on last edited by
                      #10

                      you are getting the error because you are not specifying the data type for the method arguments:

                      public int credit(_balance , _amount)
                      {
                      return _balance + _amount;
                      }
                      public int debit(_balance , _amount)
                      {
                      return _balance - _amount;
                      }

                      TRY:

                      public int credit(int _balance , int _amount)
                      {
                      return _balance + _amount;
                      }
                      public int debit(int _balance , int _amount)
                      {
                      return _balance - _amount;
                      }

                      1 Reply Last reply
                      0
                      • A ademsandeepreddy

                        iam getting identifier expected

                        hi

                        L Offline
                        L Offline
                        Luc Pattyn
                        wrote on last edited by
                        #11

                        Visual Studio will show numbers at the left of your source lines for you, and the error messages it generates include file name and line number; look at the first error you have, go investigate that particular line, (try to) fix it and recompile. Until everything is OK. :)

                        Luc Pattyn


                        try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


                        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