I am honestly too lazy to input hundreds of values into the calculator and calculate every their average & uncertainty, so here’s me automating this process.

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main(){
string val;
vector<double> valVctr;
cin.ignore(1);
do{
getline(cin, val);
if(val.size() == 0){
break;
}
valVctr.push_back(atof(val.c_str()));
}while(true);

cout << "A total of " << valVctr.size() << " values have been entered." << endl;

double sum = 0;

for(unsigned i = 0; i < valVctr.size(); i++){
sum += valVctr.at(i);
}

double average = sum/valVctr.size();

cout << "The average value is: " << average << endl;
sum = 0;
for(unsigned i = 0; i < valVctr.size(); i++){
sum += pow(average-valVctr.at(i), 2);
}
cout << "The uncertainty is: \u00B1" << sqrt(sum/(valVctr.size()-1)) << endl;
}

1. Jay
2 years ago
2021-6-08 11:33:49

oh yes i love doing homework by not doing homework

2. xiang-
5 months ago
2023-5-02 20:17:43

酷，我目前也在大学里学c++

## Send CommentEdit Comment

|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
（╯‵□′）╯︵┴─┴
￣﹃￣
(/ω＼)
∠( ᐛ 」∠)＿
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ｀)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ(￣∇￣o)
ヾ(´･ ･｀｡)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò｡)
Σ(っ °Д °;)っ
( ,,´･ω･)ﾉ"(´っω･｀｡)
╮(╯▽╰)╭
o(*////▽////*)q
＞﹏＜
( ๑´•ω•) "(ㆆᴗㆆ)

Emoji