Here is problem I couldn\'t figure out: Write a function called getLabGrades tha
ID: 647984 • Letter: H
Question
Here is problem I couldn't figure out:
Write a function called getLabGrades that prompts the user for each assignment grade (there are 5). Remember that each lab is worth 120 points. Use the following code in main to call it:
int main() {
double labs = getLabGrades();
cout << "Your lab grade is: " << labs << endl;
return 0;
}
Sample output:
Please enter best grade for lab 1: 100
Please enter best grade for lab 2: 95
Please enter best grade for lab 3: 90
Please enter best grade for lab 4: 85
Please enter best grade for lab 5: 80
Lab grade: 540
Your lab grade is: 540
Explanation / Answer
==================================
int main()
{
double labs = getLabGrades();
cout << "Your lab grade is: " << labs << endl;
return 0;
}
====================
Try this :
double getLabGrades()
{
double total = 0, grade = 0; // grade = grade for the students at the moments
int counter = 0;
const int numlabs = 5;
while (counter < numlabs)
{
cout << "Please enter best grade for lab " << counter + 1 << ": ";
std::cin >> grade;
if (grade > 120 || grade < 0)
{
while (grade < 0 || grade>120)
{
std::cout << "Check the score again, Try with the currect grade " << counter + 1 << " : "; // wrong score popup
std::cin >> grade;
}
}
total += grade;
++counter;
}
return total;
}