//exercise 5.5; control instructions 2
//Luis Fernando
//18/09/2018
/*Write a program that uses an instruction for to add up a sequence of integers. Suppose that the first integer read specifies the number of values that miss for introducing. Your program must read only a value for every instruction
Of entry. A typical sequence of entry might be
5 100 200 300 400 500
Where 5 indicates that they are going to add up 5 subsequent values.
*/
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main(int argc, char** argv)
{
int number;
int numberSum;
int storeTotalSum = 0;
cout << "Join the numbers to add up " ;
cin >> number;
for(int counter = 0; counter < number; counter++)
{
cout << "add a number to add up: ";
cin >> numberSum;
storeTotalSum += numberSum;
}
cout << "it´s going to add up " << number << " integers." << endl;
cout << "the sum is: " << storeTotalSum << endl;
return 0;
}
This looks like the standard pattern for this kind of homework. The only thing I would not do is continue to ask for input (line 31); the user already knows the number of integers he wishes to input, but it doesn't really matter either way.
Also, be careful when you are talking to the user:
1 2 3
cout << "How many numbers do you wish to add? ";
--or--
cout << "¿Cuántos números deseas sumar? ";
Likewise, tell the user what to do:
1 2 3
cout << "Enter a number: ";
--or--
cout << "Ingrese un número: ";
Don't tell things that happened out of chronological order. At the end of the program the numbers have already been added:
1 2 3
cout << number << " integers were added.\n";
--or--
cout << "Se sumaron " << number << " integeres.\n";