1.

Solve : [Help] Could you identify the errors in the code ??

Answer»

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: ");
}
}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
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.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.

Quote from: DaveLembke 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.

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



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


Discussion

No Comment Found