+ 1
Why this program doesn't work properly?
First question: Why doesn't this program work as intended? When I run it and enter 6 values it shows the sum as 5 and average as 0 and totally ignores the numbers I have entered. (In computer) Second: What can I do that this program receives unlimited numbers? Third: How can I set the program that calculates the average on its won, since the user might enter 5 numbers or 10 numbers? (I mean the program understands the number of entered numbers on its own) https://code.sololearn.com/chiy4s9Jyv4U/?ref=app
2 Answers
+ 1
cin >> a, b, c, d, e, f; is just takes one input to a, next are just no effect statement
Correct way is :
cin >> a >> b >> c >> d >> e ;
Accepts 5 inputs...
Or you can separate for clarity.. Like :
cin >> a;
cin >> b;
...
For unlimited input, use a loop, repeat until cin fails to take input. You may need use a vector type as it grows it's size automatically..
And also vector.size() returns how many values you entered. Or you can increment a counter in loop..
+ 1
Jayakrishnaš®š³ thank you so much.