The for statement

Can someone help me do this question?

"Write a for loop that computes the sum of the odd number from 1 to a maximum value entered by the user."

please help me, my teacher isn't helping me that much
I could help but I do not know what is the maximum value of the user.:)
The user should decide what maximum value he/she will be using.
Tell your teacher about arithmetic progression's sum :)

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

using namespace std;

const unsigned int user_number = _USER_NUMBER_

unsigned long long sum = 0;
for (unsigned int z = 1; z < user_number; z++)
   sum += z;

cout << sum << endl;
I need a for loop statement in it :(
1
2
3
4
for (unsigned int z = 1; z <= user_number; z += 2)
   sum += z;

cout << sum << endl;


Odd numbers go up in steps of 2.
Never mind the question, my teacher changed it into:

"Write a for loop that computes the sum of every number from 1 to the MAXIMUM VALUE that the user entered"

Need help :(
There's plenty of help already here is this thread.

The only bit left for you to do is to get the user input.
Yep I got it!

just changed z += 2 into z ++ .

Great, Thanks Chervil, I got a perfect score :3
I got a perfect score

That's only part of the job. The important part is to understand and learn this topic :)
Topic archived. No new replies allowed.