## tuffyg

``````package farecalc;

import java.io.*;
public class FareCalc   {
public static void main (String[] args) throws IOException    {

double firstMile = 2.80;
double otherMile = 1.20;
String mileageInput = in.readLine();
double mileage = Integer.parseInt(mileageInput);

double price = firstMile + (otherMile * (mileage - 1));

System.out.println("Your fare is £" + price);

}

}``````

what it should do is take a mileage and work out a cost to it. e.g. 2miles = £4
it works if its a whole number but not if there is a decimal e.g. 2 works 2.1 doesn't.

can anyone help?

thanks

## Mehaboob.pasha

``````package farecalc;

import java.io.*;
/*
public class FareCalc   {
public static void main (String args[]) throws IOException    {

double firstMile = 2.80;
double otherMile = 1.20;
String mileageInput = in.readLine();
double mileage = Integer.parseInt(mileageInput);

double price = firstMile + (otherMile * (mileage - 1));

System.out.println("Your fare is £" + price);

}

}``````

what it should do is take a mileage and work out a cost to it. e.g. 2miles = £4
it works if its a whole number but not if there is a decimal e.g. 2 works 2.1 doesn't.

can anyone help?

thanks

I have made the correction please check it whether it will work or not......... your welcome...... :)

## majestic0110 187

On line 15, you are parsing the user input to an integer, and integers do not function with decimals. Parse the input string to a double:

``double mileage = Double.parseDouble(mileageInput);``

## tuffyg

On line 15, you are parsing the user input to an integer, and integers do not function with decimals. Parse the input string to a double:

``double mileage = Double.parseDouble(mileageInput);``

hi thank you both for your replies
1. mehaboob i dont know what you did but it didn't work (but thank you for trying)
2. majestic.
.it ..... worked . Thanks

i tried putting

``double mileage = int.parseInt(mileageInput);``

before and it didn't work. i kicked myself when i found out what i did wrong lol.

thanks

## majestic0110 187

You are welcome, it's often the obvious things that we all miss! Please mark the thread as solved!