Hi every
I am doing over my programming final project trying to see where I have gone wrong. And slowly am beginning to see some of my mistakes, I guess I was a bit overwhelmed anyway, the is part is where I was and still a bit confused.
What is the four questions that have to be asked in order for the players to input the numbers from the smallest to the largest. As you can see this is the first part of the program that need to be builds. This is just round 1. The numbers have to be generated randomly and repeatedly in order for the players to answer and in case the player answers incorrectly, the game should automatically go to the second player. What can I do to get this to happen?
This is round 1
This round consists of four questions, questions 1 through 4. For each question in this round, four (4) random numbers, between 1 to 15, must be generated. The player is then required to re-arrange or enter the numbers from smallest to largest based on the four (4) generated numbers.
here is my codes
Scanner keyin = new Scanner (System.in);
Random randobj = new Random();
int user1age, user2age,count = 0;
String user1name, user2name;
int ans = 0, scores = 0;
System.out.println("Hi Welcome Students!!!");
System.out.println("To the school of counting numbers!!!!");
System.out.println("This school will teach you how to count numbers");
System.out.println("I am going to implement a game of counting but will need two players");
System.out.println("Is there anyone who is interested");
System.out.println("The rules of the game goes like this");
System.out.println("The players must between the ages of 5 and 10");
System.out.println("They must not be older or younger, the comprise of three attempt");
System.out.println("Each players is given three chances to get the correct answer and if not the game goes to the second players");
System.out.println("Do you students think that you are up for the challenge");
System.out.println("well lets have some fun");
System.out.println("Here we go then");
System.out.println("*******************************************************************");
System.out.println("hi honey what is your name");
user1name = keyin.next();
System.out.println("hi honey what is your age");
user1age = keyin.nextInt();
while(user1age < 5 || user1age > 10)
{
if(user1age < 5 || user1age > 10)
{
System.out.println("dan d police!!!! she to young to play this game");
}
else
{
System.out.println("you can play the game");
count++;
}
System.out.println("hi sweetie tell me what is your name");
user2name = keyin.next();
System.out.println("hi sweetie tell me what is your age");
user2age = keyin.nextInt();
while(user2age < 5 || user2age > 10)
{
if(user2age > 5 || user2age > 10)
{
System.out.println("dan you are too old for this game");
}
else
{
System.out.println("you can play this game");
count++;
}
while(user1age < 5 || user1age > 10 && user2age > 5 || user2age > 10)
{
System.out.println("what is user1age");
user1age = keyin.nextInt();
System.out.println("what is user2age");
user2age = keyin.nextInt();
System.out.println("neither of the two of you can play this game");
break;
}
while(user1age > 5 || user1age < 10 && user2age > 5 || user2age < 10)
{
System.out.println("what is user1age");
user1age = keyin.nextInt();
System.out.println("what is user2age");
user2age = keyin.nextInt();
System.out.println("welcome both players to the game");
break;
}
System.out.println("**************welcome to round 1*********");
System.out.println("*******user1 you are up first************");
System.out.println("user1 you are required to re-enter the numbers from the smallest to larges based on the four (4) generated numbers ");
}
for(int i =1; i<5; i++)
{
System.out.println("Random Number ["+ (i+1) + "] : " + (int)(Math.random()*15));
}
System.out.println("enter the smallest number");
int num1 = keyin.nextInt();
if(num1 == ans)
{
System.out.println("yuh gt gyal, congrat!!");
int numtries = 1;
scores = 10;
count++;
}
else
{
System.out.println("the answer is incorrect, try again");
int numtries=1;
scores -=5;
}
System.out.println("enter the next subsequent number");
int num2 = keyin.nextInt(); if(num2 == ans)
if(num2 == ans) - for some reason the compiler is not reading this condition at all, it skit it
{
System.out.println("answer correct, excellent!!!");
int numtries = 1;
scores = 10;
}
else
{
System.out.println("incorrect, \n try again");
count++;
scores -= 5;
}
System.out.println("enter the next subsequent number");
int num3 = keyin.nextInt();
if(num3 == ans)- the same for here, it skip here and read the last condition even when you entered the correct answere
{
System.out.println("answer correct, excellent!!!");
int numtries = 1;
scores = 10;
}
else
{
System.out.println("incorrect, \n try again");
count++;
scores -= 5;
}
System.out.println("enter the largest number");
int num4 = keyin.nextInt();
if(num4 == ans)
{
System.out.println("answer correct, excellent!!!");
int numtries = 1;
scores = 10;
count++;
}
else
{
System.out.println("incorrect, \n try again");
int numtries = 1;
count++;
scores -= 5;
}
}
}
}
here is my output. I am going to show you where i am recieving an output that I dont understand
run:
Hi Welcome Students!!!
To the school of counting numbers!!!!
This school will teach you how to count numbers
I am going to implement a game of counting but will need two players
Is there anyone who is interested
The rules of the game goes like this
The players must between the ages of 5 and 10
They must not be older or younger, the comprise of three attempt
Each players is given three chances to get the correct answer and if not the game goes to the second players
Do you students think that you are up for the challenge
well lets have some fun
Here we go then
*******************************************************************
hi honey what is your name
ashleigh
hi honey what is your age
4
dan d police!!!! she to young to play this game
hi sweetie tell me what is your name
leah
hi sweetie tell me what is your age
13
dan you are too old for this game
what is user1age
3
what is user2age
16
neither of the two of you can play this game
what is user1age
7
what is user2age
8
welcome both players to the game
**************welcome to round 1*********
*******user1 you are up first************
user1 you are required to re-enter the numbers from the smallest to larges based on the four (4) generated numbers
Random Number [2] : 4
Random Number [3] : 12
Random Number [4] : 12
Random Number [5] : 13
enter the smallest number
4
the answer is incorrect, try again - this is the else part of the condition it was supposed to read the first condition if the answser read in correct and if not then it read the else
enter the next subsequent number - this is the second condition which the compiler didnt read
12
enter the next subsequent number- it is the same as abover
12
incorrect, - here it read the else condition not the first
try again
enter the largest number
13
incorrect, -again it read the else condition
try again
BUILD SUCCESSFUL (total time: 1 minute 2 seconds)
and another this is; if numbers are generated from: 0, 2,5,6, and you entered 0 as the smallest, the compiler reads it as correct
but when it generated numbers from: 1, 5, 8,6 and u entered 1 as the smallest go right up to the largest
the compiler read it as incorrect. why is that.
divinity02
6
Posting Whiz in Training
Recommended Answers
Jump to Postcan you please edit your post. make a separation between your code, your analysis and your actual question. it's pretty hard to make anything out.
Your question itself should be short and to the point, so we'll quickly know what to look for, the rest, which are basically tools for …
Jump to PostI think you misunderstood what stultuske was saying. What he means is that then you post to Daniweb,the code section and only the code section should be pasted into the message using the Code button, while the actually text of the message should be entered with the normal editing window.
…
Jump to Postwhat do you mean "is not reading this condition" ?
why didn't you implement a loop instead of having all those if-else blocks?Did you debug? did you check the value for num3 and ans?
Jump to PostAgain, I would need to see both the function you have written, and the error message you are getting, before I could have any hope of answering that question. Sorry to harp on this again and again, but you need to give us all the information needed to understand what …
Jump to Postdivinity02 has started 38 threads in the Java forum over the last seven months and is still unwilling to ask sensible questions or post proper error messages. None of those threads has ever achieved "solved" status. Maybe we are all wasting our time here.
All 19 Replies
stultuske
1,116
Posting Maven
Featured Poster
divinity02
6
Posting Whiz in Training
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
divinity02
6
Posting Whiz in Training
divinity02
6
Posting Whiz in Training
stultuske
1,116
Posting Maven
Featured Poster
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
divinity02
6
Posting Whiz in Training
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
divinity02
6
Posting Whiz in Training
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
divinity02
6
Posting Whiz in Training
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
divinity02
6
Posting Whiz in Training
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
divinity02
6
Posting Whiz in Training
Schol-R-LEA
1,446
Commie Mutant Traitor
Featured Poster
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
divinity02
6
Posting Whiz in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.