Beginner Exercise Help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

#include <iostream>

int main()
{

int a = 1;
int sum = 0;

while (a <= 10)
{

    sum += a;
    a++;

}
std::cout << "Answer: " << sum <<std::endl;
return 0;
}





how can i do this with the decrement operator and how do i become a more advance programmer
Last edited on
how can i do this with the decrement operator

You're already using the decrement operator.

However, your while loop will loop infinitely until you attempt to decrement past the largest possible negative value of an int. Is that what you intended?

how do i become a more advance programmer

The same way you become more advanced at anything:

1) Practice
2) Read books and tutorials that teach you more
3) Practice
4) Seek advice from experts in the field
5) Practice
Sorry that was meant to be ++ i was trying to figure it out but keep getting 0 what books should i switch to (btw im using primer)
you can try :
1
2
3
4
5
6
int a=10;
int sum=0;
while(a>0){
 sum+=a;
 a--;
}


exactly the opposite of the increment version
Last edited on
Topic archived. No new replies allowed.