Hw Help

Pages: 12
Write a program that displays the sum of all integers between 0 and 100 (inclusive). Then
display the sum of all even integers between 0 and 100 (inclusive). Then display the sum of all
odd integers between 0 and 100 (inclusive).
Last edited on
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
#include <iostream>

using namespace std;

int main()
{
    cout << "5050\n2550\n2500\n";
    return 0;
}
Kemort's program highlights the need for some clarification from your professor (assuming that this is a homework problem). Are you expected to compute the values with loops, or using the formula for an arithmetic series, or just work out the answers by hand with the formula and print the result?
Obviously, what's expected is that you just go into the Internet and find someone who will, free of charge, give up their time to do your homework for you. Because, obviously, that's how it works in Entitled Student Land.
OP: kemort has given you a good start and you may also consider chucking in a few more, newer C++ stuff like auto return, delctype etc for some extra credit:
1
2
3
4
5
6
#include <iostream>

auto main() -> decltype(0)
{
    std::cout << "5050\n2550\n2500\n";
}


closed account (48T7M4Gy)
Time to share my newly found knowledge on tuples with gunnerfunners fine effort. Shaping up to be a winner with the prof.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <tuple>

auto main() -> decltype(0)
{
    std::tuple<int,int,int> homework(5050, 2550, 2500);
    std::cout
        << std::get<0>(homework) << '\n'
        << std::get<1>(homework) << '\n'
        << std::get<2>(homework) << '\n';
}
excellent idea kemort, now let's template it and chuck in an operator overload:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <tuple>

template <typename T>
std::tuple<T, T, T> homework(const T& a, const T& b, const T& c)
{
    std::tuple<T, T, T> free_rider{a, b, c};
    return free_rider;
}
template <typename T>
std::ostream& operator << (std::ostream& os, const std::tuple<T, T, T>& free_rider)
{
    os << std::get<0>(free_rider) << "\n";
    os << std::get<1>(free_rider) << "\n";
    os << std::get<2>(free_rider) << "\n";
    return os;
}

auto main() -> decltype(0)
{
    std::tuple<int, int, int> free_rider{5050, 2550, 2550};
    std::cout << free_rider;
}

PS: OP I'm going to stop here for now but I hope this gives you some ideas to proceed and how this forum works, do come back with your next assignment(s)
Last edited on
I like the original solution best, KISS and all that.

Gentlemen, I salute you all. You have collectively won the internet.
closed account (48T7M4Gy)
You have collectively won the internet.


Thanks @jonnin. I am now about to download my share of the prize.
While I'm away I'd like you to take care of any questions from OP.

https://www.youtube.com/watch?v=mVmPgaiq7Hw
Gentlemen, I salute you all. You have collectively won the internet.

I have a different take. I think you have collectively demonstrated what's bad about the internet. Please reread the entire thread. A brand new user asks a question and is met with taunts and jokes. Sure the OP didn't post his work etc. etc. but many new users don't. Frankly he doesn't deserve the abuse you've given him (or her).

All of you are valuable contributors to the forum. I look forward to more of the same.
closed account (48T7M4Gy)
Does that mean we have to give the prize back, Dave? My download is already underway.

https://www.youtube.com/watch?v=uBHPmYIxaiI
Last edited on
dhayden: you'd been active on the forum while this thread was underway, you should have engaged the OP yourself then rather than being oh-so-sanctimonous now
I share dhayden's views on this sorry exhibition.
I do not believe that he was just being oh-so-sanctimonous [sic]; he is the only one who tried to help a newbie.
he is the only one who tried to help a newbie.

how? when? where?
closed account (48T7M4Gy)
And now from Borges' namesake with a musical interlude to calm the police down
https://www.youtube.com/watch?v=RtDX1Vl-Jxk
you should have engaged the OP yourself then rather than being oh-so-sanctimonous now

I did try to engage the OP. See the third post in the thread.
http://www.cplusplus.com/forum/beginner/209278/

above thread was started by a user with a very offensive, sexist handle name, the a/c has now been closed. incidentally it was kemort who first noticed and objected, later I joined him/her. nobody else on this forum raised a pipsqueak including the venerable JLBorges who is so upset now but posted a detailed reply to that idiot
so before you accuse us of anything take a good look at yourselves
Last edited on
closed account (48T7M4Gy)
I did try to engage the OP. See the third post in the thread.


No you didn't. You came 12 hours after the fact. Get over it princess, the OP was long gone and to top that off somebody banned them by the look of it.

There was no abuse and no taunts. You got it wrong. Move on.
For the record, I look at the post/question; more often than not, I'm unaware of the name of the poster. One thing I definitely don't do is discourage any beginner from trying to learn C++.

Had you not striven so hard to vociferously and repeatedly defend your wanton uncouth behaviour that you had exhibited in this thread by pointing at assorted straw-men, I would have said that you ought to be ashamed of yourself. Now I realise that those would be wasted words; you are beneath contempt as far as I am concerned.

That's it; I'm off this thread.
I look at the post/question;

as i mentioned to kemort on the other thread so do i and that's why i'd initially replied to that idiot
if you only look at posts then at least you'd have seen kemort's, no?
it's all very well being good at C++ etc but when the time came to raise your voice you failed miserably
Pages: 12