...

View Full Version : Positive integers



sbear
05-11-2006, 06:42 AM
I'm stuck on a certain question. am able to do most but need help on the very first section...



Write a program which takes a series of positive integers as input : 1, 2, 3
When input is complete, as indicated by entry of an end of data flag ( -2), the program will output the largest of the entered values

Kor
05-11-2006, 07:27 AM
can you detail a little bit? I don't quite understand. ...and... you are looking for the largest (? what do you mean by that ? the lenght of the string?or what?) or for the bigger?

jscheuer1
05-11-2006, 07:35 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Max</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function findMax(){
var args=arguments, val=flag=0;
for (var i_tem = 0; i_tem < args.length; i_tem++)
if (args[i_tem]*1==-2){
args.length=i_tem+1
flag=1
}
if (flag){
for (i_tem = 0; i_tem < args.length; i_tem++)
val=Math.max(args[i_tem]*1, val)
return val
}
else {
alert ('Expected Terminator: -2, is missing.')
return 'error'
}
}
</script>
</head>
<body>
<input type="button" value="Case 1" onclick="alert(findMax(1,10,2,20,-2,30));"><span>1,10,2,20,-2,30</span><br>
<input type="button" value="Case 2" onclick="alert(findMax(1,10,-2,20,2,30));"><span>1,10,-2,20,2,30</span><br>
<input type="button" value="Case 3" onclick="alert(findMax(1,10,2,20,2,30));"><span>1,10,2,20,2,30</span><br>
</body>
</html>

Philip M
05-11-2006, 08:35 AM
Many people think that it is not a good idea to do student's homework for them when they have not produced anything themselves. sbear will never learn if he simply copies what someone else has done. And I very much doubt whether the tutor will believe that this elegant script is sbear's own work. So in future he will suspect sbear of cheating every time he sends in a correct answer. All very counter-productive in the long run.

jscheuer1
05-11-2006, 10:30 AM
Many people think that it is not a good idea to do student's homework for them when they have not produced anything themselves. sbear will never learn if he simply copies what someone else has done. And I very much doubt whether the tutor will believe that this elegant script is sbear's own work. So in future he will suspect sbear of cheating every time he sends in a correct answer. All very counter-productive in the long run.

Quite true. Couldn't have said it better myself. I was also thinking though, if sbear were clever enough, he would make the work his own by at least writing it in his own style. Perhaps even looking up references to things he didn't understand, then he would do well and learn something. However, if he were stupid enough to take someone's work as his own, he deserves the fate you so accurately describe.

Thank you for providing me the opportunity to clarify this and for expressing so well what needed to be said.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum