Computing.Net > Forums > Programming > stuff stuff

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

stuff stuff

Reply to Message Icon

Name: c_pantel
Date: October 10, 2005 at 14:33:12 Pacific
OS: -
CPU/Ram: -
Comment:

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!!!



Sponsored Link
Ads by Google

Response Number 1
Name: FBI Agent
Date: October 11, 2005 at 09:49:33 Pacific
Reply:

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 well

here'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


0

Response Number 2
Name: c_pantel
Date: October 11, 2005 at 11:43:03 Pacific
Reply:

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

Macs Suck!!!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Bidirectional pipes Easting & Northing Co...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: stuff stuff

OS stuff www.computing.net/answers/programming/os-stuff/11479.html

Some similar to vb stuff? www.computing.net/answers/programming/some-similar-to-vb-stuff/5422.html

Z80 Stuff www.computing.net/answers/programming/z80-stuff/6751.html