Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Adding 2 object fields

SweetPSweetP Member Posts: 35
I'm trying to add two object fields and assign the total to sum:

int sum = ((objmilli.millimeters) + (objcenti.centimeters));

I keep getting an error. Can you tell me what's wrong with my syntax ?

Thanks.....

Pete

Comments

  • IllcoIllco Member Posts: 382
    Maybe it would be nice to send in the error message as well... And I question what the purpose of adding centimeters and millimeters might be...

    Besides all that, check the following:
    - you have a rightly instantiated object objcenti
    - you have a rightly instantiated object objmilli
    - both contain the corresponding variables marked [b]public[/b]
    - both are integers (typed [b]int[/b]
  • chamsterchamster Member Posts: 662
    The error message would be a great help but a possibility (not the only one but a common one) might be that the fields are declared as private.


    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • SweetPSweetP Member Posts: 35
    I figured out my problem.... It wasn't syntactical....

    Thanks for the reply though....

    Pete

    : Maybe it would be nice to send in the error message as well... And I question what the purpose of adding centimeters and millimeters might be...
    :
    : Besides all that, check the following:
    : - you have a rightly instantiated object objcenti
    : - you have a rightly instantiated object objmilli
    : - both contain the corresponding variables marked [b]public[/b]
    : - both are integers (typed [b]int[/b]
    :

  • SweetPSweetP Member Posts: 35
    I figured out my problem.... It wasn't syntactical....

    Thanks for the reply though....

    Pete

    : The error message would be a great help but a possibility (not the only one but a common one) might be that the fields are declared as private.
    :
    :
    : Kind Regards
    : Konrad
    : ----------------------------
    : (+46/0) 708-70 73 92
    : chamster@home.se
    : http://konrads.webbsida.com
    :
    :

  • SweetPSweetP Member Posts: 35
    One more thing... I know the problem is a little abnormal, by adding two different units of measurement, but that's what we're asked to do... So I just do it :)

    Pete

    : Maybe it would be nice to send in the error message as well... And I question what the purpose of adding centimeters and millimeters might be...
    :
    : Besides all that, check the following:
    : - you have a rightly instantiated object objcenti
    : - you have a rightly instantiated object objmilli
    : - both contain the corresponding variables marked [b]public[/b]
    : - both are integers (typed [b]int[/b]
    :

  • chamsterchamster Member Posts: 662
    Nice to hear.



    Kind Regards
    Konrad
    ----------------------------
    (+46/0) 708-70 73 92
    chamster@home.se
    http://konrads.webbsida.com

  • Shawn CarterShawn Carter Member Posts: 0

    ______ | http://forcoder.org | free ebooks and video tutorials about [ PHP C++ Perl Python MATLAB Assembly R C Visual Basic .NET C# PL/SQL Delphi JavaScript Objective-C Go Scratch Visual Basic Swift Java Ruby Erlang Prolog VBScript ABAP Rust Transact-SQL Bash Kotlin Clojure Logo Scala Lisp F# Dart Awk Ada Hack D LabVIEW Julia COBOL FoxPro Fortran Lua ML SAS Crystal Apex Scheme Alice ] ______

Sign In or Register to comment.