We are working in a packaging factory where 100 boxes are packed in a day where each weigh around 1 Kg. To maintain sufficient accuracy, the machine picks 5 boxes in a row and find the average weight. The same processis repeated for all the packages. The average weight should be in a limit of 1 Kg ±2%. The average weight should be stored in an array. It should also report the index of boxes not satisfying the weight criteria.
#include <iostream>
#include <vector>
using namespace std;
double w[100];
double avg[20];
vector<int> notsatisfies;
int main()
{
for(int i=0; i<100; i++) {
cin>>w[i];
if (0.98 > w[i] || 1.02 < w[i])
notsatisfies.push_back(i+1);
}
for(int i=0; i<20; i++) {
avg[i]=(w[5*i]+w[5*i+1]+w[5*i+2]+w[5*i+3]+w[5*i+4])/5;
}
return 0;
}
Comments
Leave a comment