468,161 Members | 1,952 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,161 developers. It's quick & easy.

Cents to dollars program won't work...PLEase Help

nyy
this program is supposed to give the user the ability to enter numbers
in cents and tell you how many dollars you have. PLease anybody can
tell me what's wrong. Thx.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cents to Dollars</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function calcCents {
var cents = document.money.cents.value;
var dollars = 0;
var dollars = cents / 100;
var change = cents % 100;
if (change != 00)
window.alert("The number of cents you entered is equal to $" +
dollars + ".00");
else
window.alert("The number of cents you entered is equal to $" +
dollars);

}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="money" action="">
<p>Cents: <input type="text" name="cents" /><br />
<input type="button" value="Cents to Dollars" onclick="calcCents();"
/></p>
</form>
</body>
</html>

Sep 20 '05 #1
3 2922
Lee
nyy said:

this program is supposed to give the user the ability to enter numbers
in cents and tell you how many dollars you have. PLease anybody can
tell me what's wrong. Thx.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cents to Dollars</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
There are no incompatible browsers in use anymore.
You don't need to hide scripts.
function calcCents {
Function declarations require a formal argument list in
parentheses, even if there are no formal arguments:

function calcCents() {
var cents = document.money.cents.value;
var dollars = 0;
var dollars = cents / 100;
var change = cents % 100;
if (change != 00)
The sense of this test is backwards, and there is no
reason to write the value zero as 00.

if (change == 0)
window.alert("The number of cents you entered is equal to $" +
dollars + ".00");
else
window.alert("The number of cents you entered is equal to $" +
dollars);

}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="money" action="">
<p>Cents: <input type="text" name="cents" /><br />
<input type="button" value="Cents to Dollars" onclick="calcCents();"
/></p>
</form>
</body>
</html>


Sep 20 '05 #2

nyy wrote:
this program is supposed to give the user the ability to enter numbers
in cents and tell you how many dollars you have. PLease anybody can
tell me what's wrong. Thx.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cents to Dollars</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function calcCents {
You have a syntax error here. It should be:

function calcCents() {

You were missing the ().
var cents = document.money.cents.value;
var dollars = 0;
var dollars = cents / 100;
You already declared dollars as a variable. There's no need for
multiple declarations.

You wanted just the number of dollars? Then:

dollars = Math.floor(cents / 100);
var change = cents % 100;
if (change != 00)
window.alert("The number of cents you entered is equal to $" +
dollars + ".00");
else
window.alert("The number of cents you entered is equal to $" +
dollars);

If you wanted just the number of dollars, then you don't even need to
check the change, right?
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="money" action="">
<p>Cents: <input type="text" name="cents" /><br />
<input type="button" value="Cents to Dollars" onclick="calcCents();"
/></p>
</form>
</body>
</html>


Hope this helps.

Sep 20 '05 #3
web.dev <we********@gmail.com> wrote in message news:11*********************@g49g2000cwa.googlegro ups.com...
If you wanted just the number of dollars, then you don't even need to
check the change, right?


I expect that depends upon what format his teach... oops - I mean he prefers.

--
S.C.
Sep 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by nyy | last post: by
4 posts views Thread by Chris Dunaway | last post: by
16 posts views Thread by luca bertini | last post: by
7 posts views Thread by Paro | last post: by
reply views Thread by foryou | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.