+ 1

Having a little trouble understanding how this works. Formula is in the description.

{ int num = 1; int number; int total = 0; while (num <= 5) { cin >> number; total += number; num++; } cout << total << endl; return 0; }

28th Nov 2016, 3:49 AM
Talkiestcobra6
Talkiestcobra6 - avatar
10 Answers
+ 7
Hello, let me try to explain... Firstly, I guess you understand the declarations on the top, moving on to the while loop, this while loop will run until num is greater then 5, which you can see by this piece of code 'while(num<=5)', so, at first the num is 1, and code will execute, telling you to input the "number" and then adding that number to "total", it will then add one to num variable, and go again to the start of the loop. So now the "num" is 2, it will again go through the things in the loop and again it will add 1 to num, which is this piece 'num++;'. And it will do that until the num reaches more then 5, in the other words while the num becomes 6, and then it will go out of the loop and print the total variable. :)
28th Nov 2016, 3:57 AM
Filip
Filip - avatar
+ 7
When you have any troubles or questions feel free to ask. :)
28th Nov 2016, 4:02 AM
Filip
Filip - avatar
+ 7
Phython is a language for beginners, that's my opinion. In the city I live in there are like more then 90% of secondary schools that teach Phython, and that's really bad in my opinion, that's a basic language not used very often and it is just a starting thing, to get into the world of programming... For example I learn C in my school, and yeah, It is just more beneficial, because you are loosing time learning something that you won't really use anywhere or anytime...
28th Nov 2016, 4:14 AM
Filip
Filip - avatar
+ 7
I've learnt everything from home, I've started with Java a while ago, like 3 years ago, and yeah, It was easier to learn other languages like C for example... The point is, you can learn by yourself, in the future, if u have anything to ask, I am here, contact me and I will try to explain the best I can. Just don't give up, and try to learn and to read as much as you can. :)
28th Nov 2016, 4:31 AM
Filip
Filip - avatar
+ 6
Sure, go ahead. :)
28th Nov 2016, 4:05 AM
Filip
Filip - avatar
+ 2
our school system in our town doesn't teach computer in general so I'm really teaching myself c++ and so far its going good but I'm still having a little bit of trouble understanding on some parts but I feel the same way as if python is kind of a bit of waste of time in the sense of write more serious programs but what i think that is sad about my school is the fact i know a bit of python 3 but I'm teaching my teacher how to teach python coding.
28th Nov 2016, 4:28 AM
Talkiestcobra6
Talkiestcobra6 - avatar
+ 1
Thank you. It makes a lot more sense : )
28th Nov 2016, 4:01 AM
Talkiestcobra6
Talkiestcobra6 - avatar
+ 1
okay so if you don't mind can i ask you one more question?
28th Nov 2016, 4:04 AM
Talkiestcobra6
Talkiestcobra6 - avatar
+ 1
My teacher at my school insist that we should learn python 3 and shes even trying to teach herself in the process but i feel as if we should c or c++. What do you think would be more beneficial for us to learn?
28th Nov 2016, 4:08 AM
Talkiestcobra6
Talkiestcobra6 - avatar
+ 1
Thanks.
28th Nov 2016, 4:33 AM
Talkiestcobra6
Talkiestcobra6 - avatar