Why this program doesn't work properly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

20th Oct 2022, 1:09 PM
Root
Root - avatar
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..
20th Oct 2022, 1:36 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 thank you so much.
20th Oct 2022, 9:52 PM
Root
Root - avatar