Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [Help] Could you identify the errors in the code ?  (Read 4026 times)

0 Members and 1 Guest are viewing this topic.

Nikhil

    Topic Starter


    Rookie
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
[Help] Could you identify the errors in the code ?
« on: June 26, 2014, 08:39:29 AM »
Hello guys!
I need to find out the errors in the following code.

// Assume Print is a real method that takes one string as an argument
public class MyClass
{
   private int myInt = 5;

   public void myFunction( string[] message )
   {
      Print( message + myInt );
   }
}

public class Main
{
   public static void Main()
   {
      MyClass instance = new MyClass();
      instance.myInt = 10;
      instance.myFunction("My number is: ");
   }
}

camerongray



    Expert
  • Thanked: 306
    • Yes
    • Cameron Gray - The Random Rambings of a Computer Geek
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Mac OS
Re: [Help] Could you identify the errors in the code ?
« Reply #1 on: June 26, 2014, 08:54:40 AM »
We do not do homework here for obvious reasons - If you just get others to give you the answers then you will not learn and the entire homework exercise is pointless.

That said, I will give you a few pointers of things to check:
  • Look at the access levels of variables in classes
  • Look at how your main method is defined
  • Look at how to define a string as a variable

DaveLembke



    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: [Help] Could you identify the errors in the code ?
« Reply #2 on: June 26, 2014, 01:24:44 PM »
While I cant give away the answer... I can point you in a direction to finding the answers...

If you type or copy paste this into a fully functional program layout. When you go to compile it or run it, the compiler debugger will point out to you where the problems are.

You should get very accustomed to using the debug messages. While sometimes it doesnt point out an exact problem such as ( ; missing or unexpected ) and you find a ; missing or an extra, and an error message can sometimes state that ( unhandled exception error ) because your missing a specific preprocessing directive.

Given that you are at this level of programming you should already be familiar with debug messages.

Nikhil

    Topic Starter


    Rookie
  • Computer: Specs
  • Experience: Experienced
  • OS: Windows 7
Re: [Help] Could you identify the errors in the code ?
« Reply #3 on: June 27, 2014, 04:26:19 AM »
It might seem that way, but this wasn't a homework. I've got my school exams coming up and I wanted to be prepared in the best possible way. So, I decided to look through some pretty high end programs. This one was way above me.
To camerongray - Thanks, your post was pretty useful.

While I cant give away the answer... I can point you in a direction to finding the answers...

If you type or copy paste this into a fully functional program layout. When you go to compile it or run it, the compiler debugger will point out to you where the problems are.

You should get very accustomed to using the debug messages. While sometimes it doesnt point out an exact problem such as ( ; missing or unexpected ) and you find a ; missing or an extra, and an error message can sometimes state that ( unhandled exception error ) because your missing a specific preprocessing directive.

Given that you are at this level of programming you should already be familiar with debug messages.

I wouldn't be able to run it in a theory exam. :)




Maleke



    Rookie

    Thanked: 6
    • Experience: Expert
    • OS: Windows 7
    Re: [Help] Could you identify the errors in the code ?
    « Reply #4 on: July 09, 2014, 08:20:28 PM »
    When paper troubleshooting I try to go through the code methodically:

    1st: Stupid checks, First I go through and check for proper semi colons, and correct number of and matching brackets
    2nd: Scope and variable errors, next I check for proper scoping and declaration of variables
    3rd: I run through the program line by line and "run" it in my head line by line.

    That should get you to get most of the answers, if not all.

    -Mal