Ok, I have to write this program for school. I'm almost done, but I need help on one part. The program runs a loop 20 times and collects A, P, C, P, P. I have that part, but I also need to find the average number of times it took. This is what I have so far:Code:#include <iostream> #include <cmath> #include <cstdlib> using namespace std; int prem(); int average(int, int); int main() { srand(time(NULL)); int a = 0, c = 0, p = 0, sum = 0, counter = 0; for (int i = 1; i < 20; i++) { while (a < 1 || c < 1 || p < 3) { switch (prem()) { case 1: a++; break; case 2: c++; break; case 3: case 4: p++; break; } cout<<"A: "<<a<<" C: "<<c<<" P: "<<p<<" Sum: "<<endl; } cout<<"Took "<<a + c + p<<" times to get APCPP"<<endl; a = c = p = 0; } cout<<"On average, it took "<<average(sum, counter)<<" boxes."<<endl; getchar(); return 0; } int prem() { return 1 + (rand() % 4); } int average(int sum, int counter) { return sum; }




Reply With Quote