-
Algorithm Problem
Can someone look at this algorithm for me and tell me why it does not compile and if it actually makes sense.
/**
* Creates a loop to determine how many frogs will take part in the race.
*/
public int Members(); //1
public int selected();
public int frogNumber();
public int Members = 0;
{
while(this.Members < 2)
this.frogNumber1 = false;
this.frogNumber2 = false;
this.frogNumber3 = false;
{
for (int frogNumber = 1; frogNumber < 3; frogNumber = frogNumber + 1)
OUDialog.confirm("Is " + this.frogNumber() + " taking part in the race");
if (selected = true)
{
frogNumber() = true;
selected++;
}
else
{
frogNumber() = false;
}
if (selected < 2)
{
OUDiag.confirm("A race must have at least two runners to be able to start");
selected = 0;
}
}
}
I get the "missing method body, or declare adstract" on the line marked //1
-
indentation would really help you.
Code:
/**
* Creates a loop to determine how many frogs will take part in the race.
*/
public int Members(); //1
public int selected();
public int frogNumber();
public int Members = 0;
{
while(this.Members < 2)
this.frogNumber1 = false;
this.frogNumber2 = false;
this.frogNumber3 = false;
{
for (int frogNumber = 1; frogNumber < 3; frogNumber = frogNumber + 1)
OUDialog.confirm("Is " + this.frogNumber() + " taking part in the race");
if (selected = true)
{
frogNumber() = true;
selected++;
}
else
{
frogNumber() = false;
}
if (selected < 2)
{
OUDiag.confirm("A race must have at least two runners to be able to start");
selected = 0;
}
}
}
Ok whats your reason why the code is not compiling?
-
I do indent and the reason it is not compiling is because it says that the variable Members is not recognised or declared, so do i declare it like I have done or do I have to declare something else.?
-
public int Members();
should be
public int members;
The same goes for the other variables.
That being said, there are lots of things wrong with the code. But that is a place for you to start.
-
You are also missing {}'s after your while loop, f (selected = true) should use == not = since a single = is assignment not comparison, you only use () after method names, not fields, and you really need to use [code] [/code] tags when posting code here so we can read it. In a nutshell, you need to re-read the tutorials on basic code structure, you're improperly using syntax all over the place.