Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
i get in error at the end where dollar is declared one last time smae with cents....
/*
*Chris Pantel
*Mr.Wiland
*Calculates sales tax final from user input of cents and dollars
*/public class Chris
{
public static void main(String[] args)
{
double rate = .06;//declares fields
double total;
double taxtotal;
EasyReader console = new EasyReader();
System.out.println("Enter amount");//displays "enter amount"
System.out.print(" Dollars: ");
int dollars = console.readInt();//stores user input amount into dollars
System.out.print(" Cents: ");
int cents = console.readInt();//stores user input amount into cents
//calculates sales tax and displays it
total = dollars + cents;
taxtotal = total*rate;
dollars = taxtotal/100;
cents = taxtotal - dollars;
System.out.println("The sales tax is " + dollars + " and " + cents + " cents");
}
}Macs Suck!!!

i dont know anything about c++ but ill guess that int dollars means that the variable dollars is an integer and if you do this
dollars = taxtotal/100;
and the taxtotal is not a multiple of 100 then you will get an error because integers must be whole numbers but may also be negative. and the same sort of thing could be happening with the cents as wellhere's an example: dollars = 45/100; // you get an error because that is not a whole number
if int does not mean integer, then sorry because i dont know anything about c++, if it is, then try the c++ equivilant of double or decimal (i think both of those allows fractions
FBI Agent
AIM: EliteAssassin187

thx all i need to do is declare dollars and cents as doubles before i do the calculations
you helped alotMacs Suck!!!

![]() |
Bidirectional pipes
|
Easting & Northing Co...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |