+ 1

Can anyone show me how to read in an unknown amount of integers. And then add them together?

Im sooo bad at programming!

29th Mar 2017, 12:11 AM
Scott
1 Odpowiedź
+ 18
There are two ways to this. User-defined loops and Sentinel-controlled loops. The former let's the program query loop count (or number of integers to be input) from the user, e.g. int count; cout << "How many integers do you want to input?"; cin >> count; for (int i = 0; i < count; i++) { // codes } Sentinel-controlled loops on the other hand, asks the user for each completed loop for continuation, e.g. bool continue = true; while (continue) { // codes cout << "Input 1 to continue" << endl; cin >> continue; } Take note that these implementations can have various forms. The above demonstrations are low-tier and can be improved.
29th Mar 2017, 12:17 AM
Hatsy Rei
Hatsy Rei - avatar