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
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);}
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.
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 change that to (You always want to create an arrow is how I remember it.)
for the 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 Code:
else
{
System.out.println("So sorry you lost $"+ result *-1);}
}
}
As for the top line, I'm not sure
-skater
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.
Re: i can't figure out whats wrong
Quote:
Originally Posted by
skaterboy987
Here's whats wrong on the last two lines
for the
change that to
(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 "=>"