Quote (Trig @ Mar 28 2013 08:33pm)
Another Question on loops...
I have this peice of my program that is supposed to show 5 sample test questions, and when i give the answer, it either tells me im wrong or right, and after the 5th one the loop should end..
here is my code;
number = (int)(Math.random() * 10);
power = Math.pow(number, 2);
System.out.println(" You are now veiwing 5 sample test question");
for (int j = 0 * 10; j < 5;)
{
System.out.println("What is the answer of the number " + number + (" raised to the power of 2 "));
power = input.nextInt();
}
yourAnswer = input.nextDouble();
if (power == yourAnswer)
{
System.out.println(" You are correct!");
}
else
{
System.out.println("You are wrong!");
}
here is the sample out put im getting...
Candidate Name:
Jeff
What is test score:
98
Enter 1 to select employment catagory
Enter 2 to select interview possibility
Enter 3 to view a sample test question
3
You are now veiwing 5 sample test question
What is the answer of the number 0 raised to the power of 2
0
What is the answer of the number 0 raised to the power of 2
12
What is the answer of the number 0 raised to the power of 2
32
What is the answer of the number 0 raised to the power of 2
34
What is the answer of the number 0 raised to the power of 2
2
What is the answer of the number 0 raised to the power of 2
the code has to be a for loop for me to get credit..
i dont know if i should have j in there as the variable or if i should have my defined variable 'number' in there
if you need additional info, let me know.
Please correct the following errors:
You must enter a message.