diff options
| author | WiserJ <[email protected]> | 2021-10-20 15:07:59 -0700 |
|---|---|---|
| committer | WiserJ <[email protected]> | 2021-10-20 15:07:59 -0700 |
| commit | 4f73ec798cba3c0c092cb203ea04709371a3a3ac (patch) | |
| tree | 1146bf98e213812e8564c31ddc9f525037ae1069 /CST116F2021-Lab4/CST116F2021-Lab4.cpp | |
| parent | p.132-133 (diff) | |
| download | cst116-lab4-jeffwoit-4f73ec798cba3c0c092cb203ea04709371a3a3ac.tar.xz cst116-lab4-jeffwoit-4f73ec798cba3c0c092cb203ea04709371a3a3ac.zip | |
average program v1
Diffstat (limited to 'CST116F2021-Lab4/CST116F2021-Lab4.cpp')
| -rw-r--r-- | CST116F2021-Lab4/CST116F2021-Lab4.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index 64adfb2..aeb76a3 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -5,9 +5,40 @@ using namespace std; -int average() +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) +{ + cout << "Please input the first value: "; + cin >> input1; + + while (input1 <= 0); + { + cout << "Please input the second value: "; + cin >> input2; + } + + while (input2 <= 0); + { + cout << "Please input the third value: "; + cin >> input3; + } + + while (input3 <= 0); + avg = (input1 + input2 + input3)/3; + + return avg; }
\ No newline at end of file |