0

Can u solve this?Take 5 values as input and find the average

https://code.sololearn.com/cULtlxwyH5Eq/?ref=app i found the avrage...but why the ans is wrong??the ans should be 6!

22nd Sep 2018, 6:23 AM
Rayeed_leo
Rayeed_leo - avatar
8 odpowiedzi
+ 1
Good Gamer Rayeed, actually, your average is coming as 6. The only problem here is that 6 is being printed in the same line right after the sum, which is 30, causing it to appear as 306. When printing your average, try: cout<<"\n"<<avg; The "\n" here is an escape sequence which essentially creates a new line. Try it now, the average should be printed in the next line.
22nd Sep 2018, 3:51 PM
Baibhab Kundu
+ 2
Good Gamer Rayeed, since you have already found the sum, the only thing left for you to do to get the average is divide the sum by the no. of observations or inputs (in your case, 5). To get that, you could do: int avg=sum/5; cout<<avg; If you had 7 inputs, you would go like: int avg=sum/7; cout<<avg;
22nd Sep 2018, 7:23 AM
Baibhab Kundu
+ 1
Run this code, and uncomment each cout line to see the difference in output produced by using different escape sequences. https://code.sololearn.com/cG567nDob4Ur/?ref=app Here I've only shown you 2 (common) escape sequences. For a list of other escape sequences, check out this link: https://en.cppreference.com/w/cpp/language/escape
22nd Sep 2018, 4:13 PM
Baibhab Kundu
0
mean=no of observations/total no of observations
22nd Sep 2018, 6:36 AM
santhoshi bogadhi
santhoshi bogadhi - avatar
0
tnx..i know how to do but i didn't know the average procesure in coding..
22nd Sep 2018, 8:52 AM
Rayeed_leo
Rayeed_leo - avatar
0
i found the aveg but its coming 300 something, the ans should be 6!! plz help me https://code.sololearn.com/cULtlxwyH5Eq/?ref=app
22nd Sep 2018, 3:22 PM
Rayeed_leo
Rayeed_leo - avatar
0
tnx..i will be glad to u!!🇧🇩😊
23rd Sep 2018, 12:39 PM
Rayeed_leo
Rayeed_leo - avatar
0
how can I give the output - average 6 https://code.sololearn.com/cULtlxwyH5Eq/?ref=app
23rd Sep 2018, 12:42 PM
Rayeed_leo
Rayeed_leo - avatar