From dece0536d375ad7155f0c7c9596e7b8a5de49022 Mon Sep 17 00:00:00 2001 From: "ansari.rayyan@outlook.com" Date: Tue, 19 Oct 2021 23:29:47 -0700 Subject: UPDATED LAB3 ANSWERS --- CST116F2021-Lab3/CST116F2021-Lab3.cpp | 39 +++++++++++++++++++-------------- CST116F2021-Lab3/LAB3Answers-Ansari.txt | 32 +++++++++++++++------------ 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/CST116F2021-Lab3/CST116F2021-Lab3.cpp b/CST116F2021-Lab3/CST116F2021-Lab3.cpp index 73af6ad..de2eaba 100644 --- a/CST116F2021-Lab3/CST116F2021-Lab3.cpp +++ b/CST116F2021-Lab3/CST116F2021-Lab3.cpp @@ -6,35 +6,40 @@ using namespace std; int main() { - int fib = 1; - int temp1 = 1; - int temp2 = 0; - int MAX; + int numAssignments; + int avgNum = 0; + int Assignment; - cout << "Enter MAX Fibbonachi number: "; - cin >> MAX; + cout << "Please enter the number of assignments in the class: "; + cin >> numAssignments; - if (MAX != 0) { - cout << fib << endl; - } - else { + if (numAssignments > 0) { + + for (int i = 0; i < numAssignments; i++) { + cout << "Please enter assignment score: "; + cin >> Assignment; + avgNum += Assignment; - cout << "0 WAS ENTERED. ENTER A DIFFERENT NUMBER FOR A SEQUENCE."; + + } + cout << endl; + cout << "The average of the assignments is: "; + cout << (float)avgNum / numAssignments; } - while (fib < MAX) - { - cout << fib << endl; - temp2 = fib; - fib = fib + temp1; - temp1 = temp2; + else { + + cout << "Insufficient number of assignments"; } + } + + //int a = 0; //cout << a++ << endl; //cout << ++a << endl; diff --git a/CST116F2021-Lab3/LAB3Answers-Ansari.txt b/CST116F2021-Lab3/LAB3Answers-Ansari.txt index 806f79f..ec0b9e2 100644 --- a/CST116F2021-Lab3/LAB3Answers-Ansari.txt +++ b/CST116F2021-Lab3/LAB3Answers-Ansari.txt @@ -515,40 +515,44 @@ int main() if (numAssignments > 0) { for (int i = 0; i < numAssignments; i++) { + cout << "Please enter assignment score: "; cin >> Assignment; avgNum += Assignment; - + } cout << endl; + cout << "The average of the assignments is: "; cout << (float)avgNum / numAssignments; - + } else { - + cout << "Insufficient number of assignments"; - + } - - + + } + OUTPUT: Please enter the number of assignments in the class: 5 -1 -1 -2 -3 -4 - -2.2 -C:\Users\ansar\source\repos\Lab3-Ansari\Debug\Lab3-Ansari.exe (process 5884) exited with code 0. +Please enter assignment score: 32 +Please enter assignment score: 45 +Please enter assignment score: 67 +Please enter assignment score: 12 +Please enter assignment score: 1 + +The average of the assignments is: 31.4 +C:\Users\ansar\Source\Repos\cst116-lab3-rayyanansari03\Debug\CST116F2021-Lab3.exe (process 11936) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . . + ------------------------------------------------- EXERCISE 6c -- cgit v1.2.3