# Math Problem

• September 14th, 2010, 11:51 AM
kidsforsale
Math Problem
Processing:

Declare a String object to hold the programmer’s name - FINISH
Declare three floating-point numbers and fill them from the Scanner input - FINISH
Add the floating-point numbers together to create a subtotal - FINISH
Calculate the tax for this subtotal, based on a tax rate of 9.25% - FINISH
Calculate the total amount, which is the sum of the tax amount and subtotal - HELP ( no error but it's giving me the wrong answer) :(

Code Java:

```String firstNameString; float firstTax; float secondTax; float thirdTax; final double taxRate = 9.25;       Scanner inputScanner = new Scanner(System.in);   firstNameString = JOptionPane.showInputDialog("Enter your name"); System.out.print("\nEnter your First Number: "); firstTax = inputScanner.nextFloat(); System.out.print("\nEnter your Second Number: "); secondTax = inputScanner.nextFloat(); System.out.print("\nEnter your Third Number: "); thirdTax = inputScanner.nextFloat();   //Display our input values System.out.println("Name: " + firstNameString); System.out.println("Total of three numbers: " + (firstTax + secondTax + thirdTax)); System.out.println("Tax " +(firstTax + secondTax + thirdTax) / taxRate); System.out.println("Subtotal Tax: "+firstTax + secondTax + thirdTax + (+firstTax + secondTax + thirdTax / taxRate));```
• September 14th, 2010, 12:12 PM
Norm
Re: Math Problem
Quote:

it's giving me the wrong answer)
Please show what the program outputs and explain why it is wrong and what you want it to be.
• September 14th, 2010, 12:22 PM
kidsforsale
Re: Math Problem
Code :

```Enter your First Number: 11.11   Enter your Second Number: 11.11   Enter your Third Number: 11.11   Name: My Code Total of three numbers: 33.329998 Tax 3.603243028795397 Total of 3 numbers + Tax: 11.1111.1111.1123.4210803573196```

• September 14th, 2010, 12:29 PM
Norm
Re: Math Problem
You left off this part:
explain why it is wrong and show what you want it to be.

The + operator does different things that can be confusing. Some times it sums two numbers to give a numeric result and some times it is used to concatenate Strings. You seem to be getting the latter. If you put what you want to be an addition inside of ()s then the two numeric operands will be added vs concatenated.
• September 14th, 2010, 12:44 PM
kidsforsale
Re: Math Problem
Quote:

Sample Data (could be used for testing):

If you input the following three values for your floating-point numbers:
50.99
75.95
53.95
The subtotal (3 numbers added) will be: 180.89
The tax will be: 16.73
The total amount including the tax will be: 197.62
(The number of your decimal places will be different)
first i want to get the answer of 9.25% of the total of 3 numbers
then i want to add that 9.25% of that number to the total or the 3 numbers

for example

Total: 33.33
9.25% of 33.33 is: ?? ( i dont know how to do it)
9.25% of 33.33 + 33.33 = ?? ( same here )
• September 14th, 2010, 01:08 PM
Norm
Re: Math Problem
Quote:

( i dont know how to do it)
Can you compute 9.25% of 33.33?
If you can do it, what are the steps you took to do it?
If you don't know what percent means, try googling to find out.
Hasn't your math training explained what percent means?
• September 14th, 2010, 02:47 PM
kidsforsale
Re: Math Problem
never mind i just dropped my programming in java class effin professor didn't explain how the eff are we gonna do that sht arggh
• September 14th, 2010, 02:51 PM
Brt93yoda
Re: Math Problem
=o! It's not the professors fault, it's your arithmetic skills.
• September 14th, 2010, 03:24 PM
Norm
Re: Math Problem
What grade level do they teach percentages?

Basic math should be a prerequisite for a programming course.
• September 14th, 2010, 03:51 PM
bardd
Re: Math Problem
Quote:

System.out.println("Subtotal Tax: "+firstTax + secondTax + thirdTax...)
It prints these numbers next to each other, so if they're all 11.11 it'll print 11.1111.1111.11
if you'll write it this way:
System.out.println("Subtotal Tax: "+(firstTax + secondTax + thirdTax)...)
it'll print 33.33
• September 14th, 2010, 03:59 PM
aussiemcgr
Re: Math Problem
Well, for future references, you calculate a percentage of something by dividing the percent by 100, then multiplying by the the number you are wanting to get the percent of.

So,
Step 1 - Problem:
9.25% of 33.33
Step 2 - Get Percent in Decimal:
0.0925 of 33.33
Step 3 - Multiply:
0.0925 x 33.33