What is the output of the program below, if the input values are 4 11 6 17 ? would it be the sum of all those value? Which of the following values will be returned if main () is called?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main ()
{
int t = 0, value = 0;
while (cin>>value)
t+= value;
cout << "the value of t is: " <<t<<endl;
return 0;
}
Do you want the user to enter a value, or have it execute with the value (11) you defined?
(When posting code you can [_code] insert code here [/_code] (without the _ ) so it gives lines numbers, and also makes it easier to read. It's also off to the right of the text box where it says "Format:", the symbol icon like "< >" is for displaying code.)
You have two variables: t and value.
t is initially 0, and value is initially 11.
When you enter more numbers, t's value will increase by that number,
and value's value will be replaced by the entered number. Hope that makes sense.
For example:
If you enter 3, then 2, then 'x', it will print