Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By DiamondSoul

Thread: i can't figure out whats wrong

  1. #1
    redbrawn06 is offline Member
    Join Date
    Oct 2011
    Posts
    3
    Rep Power
    0

    Question i can't figure out whats wrong

    There is something wrong with the last three lines and i cannot figure it out. Does anyone know?
    Thanks for your help
    Java Code:
    import java.io.*;
    public class        { 
        public static void main (String []args){
            KeyboardInputClass keyboardInput = new KeyboardInputClass();
            int tosses;
            int tossvalue;
            char betface;
            int headcount = 0;
            int tailcount = 0;
            
            // int tosses- the number of tosses
            //int tossvalue- the value of each toss
            //char betface- the face that the user chooses to bet on 
            // int headcount- number of heads resulting
            // int tailcount- number of tails resulting
            //int result- net winning in dollars
           tosses= keyboardInput.getInteger (true, 10, 1, 50, "How many tosses shall I make?");
           tossvalue= keyboardInput.getInteger (true, 5, 1,100, "How much is each toss worth (in dollars)?");
           betface= keyboardInput.getCharacter (true, 'H', "TH", 1, "Do you want to play for heads (H/h) or tails (T/t)?");
           // uses keyboard input class to get the desired input from the user
           for (int i= 0; i < tosses; i++) { //loop beginning dependent on user input
               int coin= (int) (Math.random()*12);//Generate random numbers between 0 and 11 
               if (coin < 6){ System.out.print ("H "); // if the random number generated is less than 6 it is heads
               headcount++;// increase int headcount by 1 
               }
               else { System.out.print ("T ");// if its anything else it is Tails
               tailcount++;}}
           
           // previous for loop is the random number generator
           // == is a comparison command
           System.out.println("number of heads = " + headcount);
           System.out.println("number of tails = " + tailcount);
           if (betface== 'H'){headcount= tossvalue; // if the user bets on heads the headcount will equal the value of the bet 
           tailcount= tossvalue *-1;}
           if (betface== 'T'){tailcount= tossvalue; 
           headcount= tossvalue *-1;}
           }
        int result=headcount+tailcount;
        if (result=< 0) {System.out.println ("Congrats you won $"+ result);}
        else System.out.println("So sorry you lost $"+ result *-1);}
    Last edited by JosAH; 10-17-2011 at 07:55 AM. Reason: fixed the [code] ... [/code] tags

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: i can't figure out whats wrong

    Use code tags when posting code. [code] YOUR CODE HERE [/code] and tell us what doesn't work.

  3. #3
    skaterboy987 is offline Member
    Join Date
    Sep 2011
    Posts
    56
    Rep Power
    0

    Default Re: i can't figure out whats wrong

    It's a bit easier to understand your code if you put it in tags like [.code.]Code goes here[./code.]
    Except remove the dots.

    Here's whats wrong on the last two lines
    for the
    Java Code:
    if (result =< 0)
    change that to
    Java Code:
    if (result <= 0)
    (You always want to create an arrow is how I remember it.)
    for the
    Java Code:
    else System.out.println("So sorry you lost $"+ result *-1);}
    If you're not going to use brackets you must skip a line but, not using brackets is considered sloppy coding, I reccomend this
    Java Code:
     else 
    	{
    	System.out.println("So sorry you lost $"+ result *-1);}
    	}
    }
    As for the top line, I'm not sure
    -skater

  4. #4
    coasterguy10 is offline Member
    Join Date
    Sep 2011
    Posts
    21
    Rep Power
    0

    Default Re: i can't figure out whats wrong

    Delete the curly brace the line after the "headcount= tossvalue *-1;} line" The curly brace by itself, then add another curly brace after the last curly brace you currently have. And i would highly recommend you start putting curly braces on their own lines and tabbing them so they allign with each other, that is why you were getting the errors, your braces were off. And make sure you define the class name.

  5. #5
    DiamondSoul is offline Member
    Join Date
    Oct 2011
    Posts
    83
    Rep Power
    0

    Default Re: i can't figure out whats wrong

    Quote Originally Posted by skaterboy987 View Post
    Here's whats wrong on the last two lines
    for the
    Java Code:
    if (result =< 0)
    change that to
    Java Code:
    if (result <= 0)
    (You always want to create an arrow is how I remember it.)
    Umm, no, it's an arrow for less than or equal to (<=) but for greater than or equal to it's >=.

    The way I remember it is you type it the same way you speak it. Like you say "greater than or equal to", not "equal to or greater than" so similarly you type ">=" rather than "=>"
    Fubarable likes this.

Similar Threads

  1. Whats wrong with my program?
    By jwb4291 in forum New To Java
    Replies: 7
    Last Post: 12-12-2010, 05:40 AM
  2. whats wrong with my code?
    By beandip408 in forum New To Java
    Replies: 6
    Last Post: 11-03-2010, 01:01 AM
  3. whats wrong
    By atenv in forum New To Java
    Replies: 6
    Last Post: 06-15-2010, 02:55 PM
  4. whats is wrong with this app??
    By mrajan in forum New To Java
    Replies: 4
    Last Post: 06-09-2010, 11:56 PM
  5. Whats wrong with this code?
    By bbtgirl in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 04:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •