Answer to Question #198508 in C++ for Dion Martins

Question #198508

You Just got your 1st internship as C++ developer CONGRATULATIONS, your manager gives you your 1 st task to solve below. PROBLEM SPECIFICATION Your company wants to collect the total number of age groups within the company and calculate the average age of employees and the classification (see below table) within the company. You are required to write a program in C++ that will ask the user to enter the integer age. Determine in which group allocation each employee belong (refer to table below) and calculate the total Age sum and the company average age. The program should populate a report showing all the information. The user should enter a negative value to indicate that they are done.


Description and Age group

A. Young employees From 19 till 35

B. Middle Age group 36 till 49 (inclusive)

C. Elderly 50 till 65


Please note the below points:

1. Demonstrate the use of loops to solve this problem.

2. A sentinel should be utilised.


1
Expert's answer
2021-05-26T00:00:54-0400
#include <iostream>

using namespace std;

int main() {
    
    int n = 0;
    int total_age = 0;
    int age;
    
    while (true) 
    {
        cout << "Your age: ";
        cin >> age;
        if (19 <= age and age < 35)
            cout << age << " is yound age!\n";
        else if (36 <= age and age < 49)
            cout << age << " is middle age!\n";
        else if (50 <= age and age < 65)
            cout << age << " is eldery age!\n";
        else if (age < 0) {
            break;
        } else {
            continue;
        }
        total_age += age;
        n++;
    }
    cout << "Total age sum: " << total_age << endl;
    cout << "Avarage age: " << double(total_age) / n;
    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