Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Positive integers

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <!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>
    - John

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    375
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M
    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.
    - John


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •