| | |
Missing return Statement
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 1
B]I need to do this:[/B]
In the Hi-Lo game, the player begins with a score of 1000. The player is prompted for the number of points to risk and a second promt asks the player to choose either High or Low (1 or 2). The player's choice of either High or Low is compared to random number between ! and 13, inclusive. If the number is between 1 and 6, it is considered low (1), if the number is between 8 and 13, it is considered high (2), and 7 is neutral and the player loses points. If the player guessed correctly, the points wagered are doubled and added to the total points. A wrong guess, the player loses the wagered points.
This is what I wrote:
import java.util.*;
public class HiLo
{
public static int oneRound (int choice, int wager, int points)
{
int rand;
rand = (int)(Math.random()*13 - 1);
if (choice == 1 && rand <=6)
{
return (points + wager);
}
else if (choice == 1 && rand ==7)
{
return (points - wager);
}
else if (choice == 1 && rand >= 8)
{
return (points - wager);
}
else if (choice == 2 && rand <= 6)
{
return (points - wager);
}
else if (choice == 2 && rand ==7)
{
return (points - wager);
}
else if (choice == 2 && rand >= 8)
{
return (points + wager);
}
}
public static void main(String[] args)
{
int wager;
int points = 1000;
int choice;
Scanner input = new Scanner(System.in);
System.out.println("Enter a 1 for numbers 1-6, or a 2 for numbers 8-13.");
choice = input.nextInt();
System.out.println("you have 1000 points, enter your wager.");
wager = input.nextInt();
do
{
points = oneRound(choice, wager, points);
System.out.println("You have " + points + " points left.");
}
while (wager < points || wager == 0);
}
}
The problem is that I keep getting a missing return statement
Please help
thank you
In the Hi-Lo game, the player begins with a score of 1000. The player is prompted for the number of points to risk and a second promt asks the player to choose either High or Low (1 or 2). The player's choice of either High or Low is compared to random number between ! and 13, inclusive. If the number is between 1 and 6, it is considered low (1), if the number is between 8 and 13, it is considered high (2), and 7 is neutral and the player loses points. If the player guessed correctly, the points wagered are doubled and added to the total points. A wrong guess, the player loses the wagered points.
This is what I wrote:
import java.util.*;
public class HiLo
{
public static int oneRound (int choice, int wager, int points)
{
int rand;
rand = (int)(Math.random()*13 - 1);
if (choice == 1 && rand <=6)
{
return (points + wager);
}
else if (choice == 1 && rand ==7)
{
return (points - wager);
}
else if (choice == 1 && rand >= 8)
{
return (points - wager);
}
else if (choice == 2 && rand <= 6)
{
return (points - wager);
}
else if (choice == 2 && rand ==7)
{
return (points - wager);
}
else if (choice == 2 && rand >= 8)
{
return (points + wager);
}
}
public static void main(String[] args)
{
int wager;
int points = 1000;
int choice;
Scanner input = new Scanner(System.in);
System.out.println("Enter a 1 for numbers 1-6, or a 2 for numbers 8-13.");
choice = input.nextInt();
System.out.println("you have 1000 points, enter your wager.");
wager = input.nextInt();
do
{
points = oneRound(choice, wager, points);
System.out.println("You have " + points + " points left.");
}
while (wager < points || wager == 0);
}
}
The problem is that I keep getting a missing return statement
Please help
thank you
![]() |
Similar Threads
- missing return statement (Java)
- missing return statement (Java)
- missing return statement x( (Java)
- missing return statement (Java)
- missing return statement 106 and 123, any ideas?? (Java)
Other Threads in the Java Forum
- Previous Thread: Trying to figure out how to change a couple string Arrays to Boolean arrays..
- Next Thread: Homework help (enums)
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor






