User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 456,611 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,406 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 495 | Replies: 1
Reply
Join Date: Nov 2007
Posts: 2
Reputation: rrm089 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
rrm089 rrm089 is offline Offline
Newbie Poster

Help Missing return Statement

  #1  
Nov 5th, 2007
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2007
Location: USA
Posts: 3,090
Reputation: Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold Ezzaral is a splendid one to behold 
Rep Power: 15
Solved Threads: 307
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Posting Sensei

Re: Missing return Statement

  #2  
Nov 5th, 2007
Because all of your return statements are in conditionals (the "if"s), there is not a guaranteed return path. Instead of putting the returns in the if clauses, make a variable to hold the calculation and make a single return of that value at the end of the method.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 7:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC