Answer to Question #317955 in C++ for llll

Question #317955

 Lets assume you create a system which asks the user for the number of students and the number of test scores per student. A nested inner loop, should ask for all the test scores for one student, iterating once for each test score. The outer loop should iterate once for each student and take student name as input. After taking input for 3 test scores, calculate average for each student. Take 3 test scores and 4 students.

Note: use do-while loops




1
Expert's answer
2022-03-25T12:10:05-0400
#include <iostream>
#include <iomanip>
using namespace std;


int main() {
    int num_students;
    int num_tests;


    cout << "Number of sudents: ";
    cin >> num_students;
    cout << "Number of tests: ";
    cin >> num_tests;
    cout << endl;


    int student = 0;
    do {
        student++;
        cout << "Enter data for the student " << student << endl;


        int total = 0;
        int test = 0;
        do {
            test++;
            int score;
            cout << "Test " << test << " score: ";
            cin >> score;
            total += score;
        } while (test < num_tests);


        double avg = static_cast<double>(total) / num_tests;
        cout << "Average for studemt " << student << " is "
             << fixed << setprecision(2) << avg << endl << endl;


    } while (student < num_students);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog