Ask Question
6 January, 18:55

Write a program to calculate average result for three experiments. Each experiment has three sets of test result and the user is required to enter all 3 results manually. Using nested loop structure to compute and display the average of the test results for each experiment. The sample program run is as below. Experiment 1 Enter test result 1: 10.1 Enter test result 2: 20.8 Enter test result 3: 33.4 Experiment 1 average: 21.43 Experiment 2 Enter test result 1: 23.4 Enter test result 2: 84 Enter test result 3: 54 Experiment 2 average: 53.80 Experiment 3 Enter test result 1: 56.77 Enter test result 2: 65.15 Enter test result 3: 32.01 Experiment 3 average: 51.31 Press any key to continue

+1
Answers (1)
  1. 6 January, 20:07
    0
    here is code in C++.

    #include

    using namespace std;

    //main function

    int main ()

    {

    //declare variables

    double total;

    double avg, res;

    int i, j;

    / / this loop to iterate over the Experiment

    for (i=1; i<=3; i++)

    {

    total=0;

    avg=0.0;

    cout<<"Experiment "<
    / / take input of test result for each Experiment

    for (j=1; j<=3; j++)

    {

    cout<<"Enter test result "<
    cin>>res;

    / / calculate total of each Experiment

    total=total+res;

    }

    //calculating average of each Experiment

    avg=total/3;

    / / printing the output

    cout<<"/nExperiment "<
    }

    }

    Explanation:

    Declare variables "total","res" and "avg" to store total of each expression, read test result and average of each Experiment. Outer loop run for each Experiment and take 3 test result, calculate their sum and find average. And then print the average of that Experiment. Similarly this happen for 3 time to take test result and print their average.

    Output:

    Experiment 1

    Enter test result 1:10.1

    Enter test result 2:20.8

    Enter test result 3:33.4

    Experiment 1 average: 21.4333

    Experiment 2

    Enter test result 1:23.4

    Enter test result 2:84

    Enter test result 3:54

    Experiment 2 average: 53.8

    Experiment 3

    Enter test result 1:56.77

    Enter test result 2:65.15

    Enter test result 3:32.01

    Experiment 3 average:51.31
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program to calculate average result for three experiments. Each experiment has three sets of test result and the user is required ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers