473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3062
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: nyy | last post by:
I need help on this program, it have to convert cents to dollars when you enter #of cents. Thanks please anybody can help. Thanks.
3
by: musosdev | last post by:
Hi guys Okay, I've setup my projects to open and compile fine in VS2005 using FPSE and remote web, but it's *really* slow. So I thought I'd have a go at doing it the normal way, by loading from...
9
by: bdog4 | last post by:
I want to validate a number to so that they can only input $2.00, 5.00, 7.00, 50.00 etc... I don't wan them to be able to put cents on the amount. It can either either be 2 or 2.00 Any ideas on...
4
by: Chris Dunaway | last post by:
I am writing a simple point of sale type application. One of the functions includes reading a weight from a scale and then multiplying that weight by a UnitPrice to get an amount. The scale...
16
by: luca bertini | last post by:
Hi, i have strings which look like money values (ie 34.45) is there a way to convert them into float variables? everytime i try I get this error: "numb = float(my_line) ValueError: empty string...
7
by: Paro | last post by:
If any body knows there is part time c language jobs here http://zubair.jhara.googlepages.com/jobs.html
0
by: foryou | last post by:
Earn 75 cents on every hour navigation Update!! This site is one of the sites profitability, which is one of the best types of profit and easier to open a page and leave the navigation of self...
3
by: canabatz | last post by:
i need help creating a from for input price i want two separate fields to hold dollars and cents ,and when i press on submit the all price will be sent as: lets say 12.45 how can i do it ,im...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.