aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab4/CST116F2021-Lab4.cpp
blob: decdaa053f140b0f4f7611d4268835a6029a416b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// CST116F2021-Lab4.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>

using namespace std;

float average(int, int, int, float);

int main()
{
    float avg = 0;
    int input1 = 0, input2 = 0, input3 = 0;
    
    do 
    {
        avg = average(input1, input2, input3, avg);
    } while (avg == 0);

    cout << "The average of these values is " << avg;
}

float average(int input1, int input2, int input3, float avg)
{
    do
    {
        cout << "Please input the first value: ";
        cin >> input1;
    } while (input1 <= 0);
    
    do
    {
        cout << "Please input the second value: ";
        cin >> input2;
    } while (input2 <= 0);

    do
    {
        cout << "Please input the third value: ";
        cin >> input3;
    } while (input3 <= 0);

    avg = (input1 + input2 + input3)/3;

    return avg;
}