hi everyone
I just want to say merry christmas to each and everyone here. it has been a while, yes ah kno but anyway have been doing this programming school assignment game for over two months
iam having real difficulties getting it to work the way it is supposed to work. I have re-do this game numerous time because of the logical errors that was there and couldnt figure out and still cant.
the game is like this, it has 3 round. it also has 10 questions that need to be generated using the random generator. and it supposed to go from level 1 -10
round 1 - add with 4 levels, ah mean level 1,2,3 and 4, four question. one question for each level.
round 2-subtract with 4 level, ah mean level 5, 6, 7 and 8 four questions also, one for each level
round 3 -divide with 2 level ah mean level 9, and 10 2 question one for each level
on any given level if the user enter a wrong answer, the game supposed to iterate and stay on the said level and repeated the same question until the user get it correct and it goes for all the rounds. rounds 1-3.
i am not getting it to iterate at all. I am using a while loop along with nested if else if. and right now the game is stuck on . here is my codes and the output. any help will be greatly appreciated and this has to be handed up on the 31 december 2015, dont have much time.
System.out.println("******************welcome to round 1************************");
System.out.println("Hi what is your name");
playername = userinput.next();
System.out.println(playername+" you have a very unique name, my dearest");
System.out.println(playername+" how old are you");
playerage = userinput.nextInt();
//initializing the player name and age
// this is checking to see wjther the player entered the correct age
if(playerage < 8 || playerage > 13)
{
System.out.println(playername+" you have entered an invalid age");
System.exit(0);//this indicating that the player has entered the wrong age, so the game exit
}
else
{
System.out.println(playername+" come let's play");
//this is statinf that the player entered the correct age
}
i=1;
while(i<=4)
{
if(i<=4)
{
//get random numbers
rand = 1 + randobj.nextInt(25);
rand2 = 1 + randobj.nextInt(8);
correctans = rand + rand2;
incorrectans = 25 + randobj.nextInt(50);
//inidicating the level and round the user would start with
System.out.println(playername+" round 1 "+ "level "+ i + " question "+ i + " you are required to match the letter to the corresponding answer");
System.out.println(playername+" please add "+ rand + " + "+ rand2);
//get the multiple choice answer
System.out.println("A:"+correctans);
System.out.println("B:"+incorrectans);
choice = userinput.next().charAt(0);
if(choice == 'A' || choice == 'a')
{
System.out.println(playername+" well done kiddo, correct is right, keep it up");
score += score + 650;
System.out.println("round 1");
System.out.println("level "+ i);
totalscore += score;
System.out.println("the total score is "+ totalscore);
i++;
correctans++;//to count all the correct answer entered
}
else if(choice == 'B' || choice == 'b')
{
System.out.println(playername+" no troll!! not the correct answer, you need to try again");
score -= score - 225;
System.out.println("round 1");
System.out.println("level "+ i);
totalscore -= score;
System.out.println("the total score is "+ totalscore);
i++;
wrongcount++;//to count all the incorrect ans
}
}
}
i=1;
while(chances !=0 && i<=4)
{
if(chances < 4)
{
//get random numbers
rand = 1 + randobj.nextInt(25);
rand2 = 1 + randobj.nextInt(8);
correctans = rand + rand2;
incorrectans = 25 + randobj.nextInt(50);
//inidicating the level and round the user would start with
System.out.println(playername+" round 1 "+ "level "+ i + " question "+ i + " you are required to match the letter to the corresponding answer");
System.out.println(playername+" please add "+ rand + " + "+ rand2);
//get the multiple choice answer
System.out.println("A:"+correctans);
System.out.println("B:"+incorrectans);
choice = userinput.next().charAt(0);
}
if(choice == 'A'|| choice == 'a')
{
System.out.println(playername+" keep it up, you are doing great, you have %d chances left "+ chances);
level--;
chances--;
}
else if(choice == 'B' || choice == 'b')
{
System.out.println(playername+"\n come on now!!! you have one wrong, you have %d chances lefet "+ chances);
System.out.println("round 1");
System.out.println("level "+ i);
chances--;
}
else if(chances < 3)
{
//get random numbers
rand = 1 + randobj.nextInt(25);
rand2 = 1 + randobj.nextInt(8);
correctans = rand + rand2;
incorrectans = 25 + randobj.nextInt(50);
//inidicating the level and round the user would start with
System.out.println(playername+" round 1 "+ "level "+ i + " question "+ i + " you are required to match the letter to the corresponding answer");
System.out.println(playername+" please add "+ rand + " + "+ rand2);
//get the multiple choice answer
System.out.println("A:"+correctans);
System.out.println("B:"+incorrectans);
choice = userinput.next().charAt(0);
}
if(choice == 'A' || choice == 'a')
{
System.out.println(playername+"well done, it is correct, keep going, you have %d chances left "+ chances);
System.out.println("round 1");
System.out.println("level "+ i);
chances--;
}
else if(choice == 'B'|| choice == 'b')
{
System.out.println(playername+"\n oh my that is not correct you have %d chances left "+ chances);
System.out.println("round 1");
System.out.println("level "+ i);
chances--;
}
else if(chances < 2)
{
//get random numbers
rand = 1 + randobj.nextInt(25);
rand2 = 1 + randobj.nextInt(8);
correctans = rand + rand2;
incorrectans = 25 + randobj.nextInt(50);
//inidicating the level and round the user would start with
System.out.println(playername+" round 1 "+ "level "+ i + " question "+ i + " you are required to match the letter to the corresponding answer");
System.out.println(playername+" please add "+ rand + " + "+ rand2);
//get the multiple choice answer
System.out.println("A:"+correctans);
System.out.println("B:"+incorrectans);
choice = userinput.next().charAt(0);
}
if(choice == 'A' || choice == 'a')
{
System.out.println(playername+" no right, that is correct, you have %d chances left, let keep it that way");
System.out.println("round 1");
System.out.println("level "+ i);
chances--;
}
else if(choice == 'B'|| choice == 'b')
{
System.out.println(playername+" nah man come on!!! that is incorrect you have %d chances left "+chances);
System.out.println("round 1 ");
System.out.println("level "+i);
chances--;
}
else if(chances < 1)
{
//get random numbers
rand = 1 + randobj.nextInt(25);
rand2 = 1 + randobj.nextInt(8);
correctans = rand + rand2;
incorrectans = 25 + randobj.nextInt(50);
//inidicating the level and round the user would start with
System.out.println(playername+" round 1 "+ "level "+ i + " question "+ i + " you are required to match the letter to the corresponding answer");
System.out.println(playername+" please add "+ rand + " + "+ rand2);
//get the multiple choice answer
System.out.println("A:"+correctans);
System.out.println("B:"+incorrectans);
choice = userinput.next().charAt(0);
}
if(choice == 'A'|| choice == 'a')
{
System.out.println(playername+" woot woot nice try, correct you have no %d chances left "+chances);
System.out.println("round 1");
System.out.println("level "+ i);
chances--;
}
else
{
System.out.println(playername+" game over");
}
this is the output
run:
Welcome to Summer's Eve Multiple Choice Math Program
The game consist of 3 round with 6 level
The age limit of this game is 8 - 13 years
The player wins the game if all questions are answerred correctly
The player loses the game if they run out of chances
Each player has 4 chances
Each correct answer is rewarded with a maximum of 650 points
Each incorrect answer will lose half of the alloted point given
A report is submitted at the end of the game
A player only win the game if all 10 question are answered correctly
A player loses the game if the age is entered incorrectly or if the player ran out of the chances given
okay students, I hope that I have made myself very clear
******************welcome to round 1************************
Hi what is your name
davey
davey you have a very unique name, my dearest
davey how old are you
12
davey come let's play
davey round 1 level 1 question 1 you are required to match the letter to the corresponding answer
davey please add 2 + 4
A:6
B:46
a
davey well done kiddo, correct is right, keep it up
round 1
level 1
the total score is 650
davey round 1 level 2 question 2 you are required to match the letter to the corresponding answer
davey please add 22 + 7
A:29
B:32
a
davey well done kiddo, correct is right, keep it up
round 1
level 2
the total score is 2600
davey round 1 level 3 question 3 you are required to match the letter to the corresponding answer
davey please add 5 + 2
A:7
B:43
b
davey no troll!! not the correct answer, you need to try again
round 1
level 3
the total score is 2375
davey round 1 level 4 question 4 you are required to match the letter to the corresponding answer
davey please add 21 + 2
A:23
B:67
a
davey well done kiddo, correct is right, keep it up
round 1
level 4
the total score is 3475
BUILD SUCCESSFUL (total time: 28 seconds)
this is were the game stop