0

hello there,
i need to get 7 different values for a resistor from the user,
then add them up.

how will i go about doing so?
do i store each value the user gives me all in different variables? or is there a way to store them into a single variable?
thanks
i noticed i spelled 'accumulate' incorrectly, sorry

Edited by cogitoergosum18: n/a

5
Contributors
5
Replies
7
Views
7 Years
Discussion Span
Last Post by firstPerson
0

You store the values if you need them later, you don't if you don't need them later. For the sum itself, you will only need a temporary variable to save the input but not a permanent array. To store all of them in a "single variable", that variable will have to be an array (or std::vector). This page on vectors has what you need.

0

declate a variable in which you will store the sum, declare another variable for input, and every time you get input in the input variable you add it to the sum variable, e.g:

sum += input;
0

yes, but how do i make the vector add all the integers up?

Edited by cogitoergosum18: n/a

0

With a loop:

for (int i = 0; i < vector.size(); ++i) {
  /* add them up */ 
}

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.