Results 1 to 21 of 21

Thread: h

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2020
    Posts
    1

    h

    When
    Last edited by brycekrispy; Jun 24th, 2020 at 11:24 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: How do I create a sum function?

    If you were doing this for real then you'd do it like this:
    vb.net Code:
    1. Dim sum = Enumerable.Range(1, x).Sum()
    I suspect that this is homework and you are supposed to show that you can write a loop though. If that is the case then it would be cheating for us to write the code for you. Maybe you should review the information you've been taught, put it to use and try writing the code for yourself. If you have problems along the way then we can help with that but you do still need to do your own homework for the most part. If you really wanted to cheat though, I can't imagine that it would be hard to find an example of something like this already on the web.

  3. #3
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: How do I create a sum function?

    The mathematical formula for the sum of n numbers is n * (n + 1) / 2. In the post #1 example, n is 5 so the answer is 5 * 6 / 2 which is the required 15.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: h

    The edits to the initial post has turned this into an exercise in surrealism.
    My usual boring signature: Nothing

  5. #5
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: h

    My answer to this kind of question is generally "between now and later" but has nothing to do with VB...
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: h

    I prefer jmcilhinney's and 2kaud's solutions, but the looping method is...

    Code:
    Dim sum as Integer = 0
    For x as Integer = 1 to 5
        sum += x
    Next
    MsgBox(sum.ToString)

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: h

    Quote Originally Posted by .paul. View Post
    I prefer jmcilhinney's and 2kaud's solutions, but the looping method is...

    Code:
    Dim sum as Integer = 0
    For x as Integer = 1 to 5
        sum += x
    Next
    MsgBox(sum.ToString)
    Why do you insist on cheating for people all the time? As someone who has done plenty of study and has worked for the marks they got and accepted the loss when they couldn't do the work themselves, it's frustrating to see someone continually encourage others to not bother doing their own homework. The only reason someone would need to use a loop when there are better options is because it's homework and they are required to demonstrate some specific coding technique. Why do you think it's a good idea that they get marks for work they didn't even try to do when their classmates who actually did try but may not have been able to do everything themselves will lose marks? It really is infuriating to see this repeatedly. What you do is up to you but I implore you to stop cheating for lazy students. If they are good enough to do the work then they should do it and if they're not then they don't deserve the marks.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: h

    I've studied hard myself, and i know just how disappointing it is to get worse marks than i hoped for. I wish some of my assignments just asked for a simple loop and a sum. I only answered because it appears the OP has abandoned the thread, and any programmer that doesn't know how to write a simple loop themselves is going to fall flat on their face later if they choose to just copy and paste my answer...

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: h

    Programming classes build on the subjects taught. A simple loop this week might be a more complex program requiring loops next week. Anyone copying and pasting blindly deserves to fail, and they will eventually.

  10. #10
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,140

    Re: h

    Quote Originally Posted by .paul. View Post
    Programming classes build on the subjects taught. A simple loop this week might be a more complex program requiring loops next week. Anyone copying and pasting blindly deserves to fail, and they will eventually.
    Right, but what you are doing is helping to "kick the fail" down the road. If you ran a business that hired entry level programmers straight from college, you wouldn't want to be in a position where you might be hiring someone who copied and pasted their way to a degree. Then their failure is at your expense, when their failure should be at their own expense.

    The earlier the fail is acknowledged, the better. For the person, for potential employers, for society.

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: h

    Ok. For a programmer that doesn’t know how to use a simple loop, I’d recommend a beginner’s tutorial...

    http://www.homeandlearn.co.uk

    BryceKrispy - you obviously didn’t know how to use a loop, and as no-one else here is willing to direct you to a proper explanation of how loops and variables work, I’d strongly recommend working through the tutorial...

  12. #12
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: h

    Quote Originally Posted by OptionBase1 View Post
    Right, but what you are doing is helping to "kick the fail" down the road. If you ran a business that hired entry level programmers straight from college, you wouldn't want to be in a position where you might be hiring someone who copied and pasted their way to a degree. Then their failure is at your expense, when their failure should be at their own expense.

    The earlier the fail is acknowledged, the better. For the person, for potential employers, for society.
    If I ran a business that hired entry level programmers, they’d be required to pass an exam at a suitable level of complexity, as a part of the recruitment process. I wouldn’t take qualifications as proof of anything. I’ve been to plenty of interviews myself where only those who passed an aptitude test got through to the second part of the interview...

  13. #13
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: h

    Quote Originally Posted by .paul. View Post
    Ok. For a programmer that doesn’t know how to use a simple loop, I’d recommend a beginner’s tutorial...

    http://www.homeandlearn.co.uk

    BryceKrispy - you obviously didn’t know how to use a loop, and as no-one else here is willing to direct you to a proper explanation of how loops and variables work, I’d strongly recommend working through the tutorial...
    If they have been assigned this exercise then they are already, at the very least, working through a tutorial and possibly a book or a class. In any of those cases, they've been taught how to write a loop. They were just too lazy to go back over their text, understand the principles involved and then apply those principles to this specific situation. In the extremely unlikely case that they legitimately haven't encountered instruction on writing a loop before, if someone is not capable of opening a search engine and typing in "vb.net tutorial" then we really think we're doing them or anyone else a favour by encouraging them to get into programming. I know that you want to help but there's a difference between helping and enabling. Again, what you do is up to you - I don't make the rules and you can ignore everything I say if you want - but I have very strong opinions on this subject and felt compelled to voice them because I'm pissed off over a conversation I had online on a different subject so sorry if you suffered some of the splash from that.

  14. #14
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,140

    Re: h

    My last post. You can go another round if you want, I won't respond.

    In your scenario, if said applicant elicited help from the internet to pass your complex exam, and someone else with your mindset willingly provided such assistance? Well, I suppose you could do another round of more stringent vetting. And if they got help with that round? And the next round? Yeah...

    You're not helping anyone in the long term when you do their work for them. You are obviously free to post whatever you want in homework threads, just don't be surprised when you are criticized for doing their homework for them. Like I said, it is kicking the fail down the road.

  15. #15
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,048

    Re: h

    I have to admit that I Post sometimes to much Information or should I say to much Code, I read what JMC
    is saying and I think I'll try and hold back a bit more.

    anyway I found a good video Tut. on L(H)oop's for beginners
    https://www.youtube.com/watch?v=2ZLuZh2sF9c

    the Task for every advanced programmer would be to Hoop and write
    a Loop on the Laptop
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: h

    @jm and OptionBase You’re right, they could cheat, but I was referring to a pen and paper classroom scenario
    Last edited by .paul.; Jun 24th, 2020 at 07:03 PM.

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: h

    Quote Originally Posted by ChrisE View Post
    I have to admit that I Post sometimes to much Information or should I say to much Code, I read what JMC
    is saying and I think I'll try and hold back a bit more.
    I'm guilty of it myself at times. It can depend what sort of mood I'm in. I try to gauge whether a question is likely to be homework or not and avoid just posting code to copy if I think it is. That's why I did post the sort of code you might use in a real application but not the sort of code a beginner's homework question would accept. In such cases, I will often ask the sort of questions that I think the person should be asking themselves and the answers can yield a topic that they can then research to come up with the actual answer tot heir original question. Sure, we can post links to tutorials but, to be brutally honest, anyone who can't find that sort of thing for themselves is really too dumb to be a developer or too lazy to deserve anyone's help.

  18. #18
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: h

    For a thread with a question that was almost immediately deleted, this has sure gone on a long time.
    My usual boring signature: Nothing

  19. #19
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,348

    Re: h

    Quote Originally Posted by Shaggy Hiker View Post
    For a thread with a question that was almost immediately deleted, this has sure gone on a long time.
    If the OP is just going to slink off then we may as well get some mileage out of this thread.

  20. #20
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    1,000

    Re: h

    This is the FAQ on the CodeGuru sister site re homework help.

    http://forums.codeguru.com/showthrea...ork-assignment
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  21. #21
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: h

    That's a pretty good summary of the various posts that have been made on this topic over the years.
    My usual boring signature: Nothing

Posting Permissions

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



Click Here to Expand Forum to Full Width