Question

it should be written in c++ Your program should take numbers from the user until the...

it should be written in c++

Your program should take numbers from the user until the number 0 is entered. While doing so, it will keep a running total of both the amount and the sum of numbers that are “teenagers” (between 13 and 19 inclusive) and a total amount and sum of the numbers that are not in that range. It should then, at the end of the program, output all of the “teenager” numbers one by one. Then it should output the total number of teenagers, followed by the sum of all the teenagers. Then it should output the total number of non-teenagers, followed by their sum.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

int main() {
    int age, total = 0, count = 0, total1 = 0, count1 = 0;
    string teenage, non_teenage;
    while (true) {
        cout << "Enter age(0 to stop): ";
        cin >> age;
        if (age == 0) break;

        if (age >= 13 && age <= 19) {
            teenage += to_string(age) + "\n";
            total += age;
            ++count;
        } else {
            non_teenage += to_string(age) + "\n";
            total1 += age;
            ++count1;
        }
    }
    cout << "All teenage ages are" << endl;
    cout << teenage;
    cout << "Number of teenage ages is " << count << endl;
    cout << "Total of all teenage ages is " << total << endl;
    cout << "All non-teenage ages are" << endl;
    cout << non_teenage;
    cout << "Number of non-teenage ages is " << count1 << endl;
    cout << "Total of all non-teenage ages is " << total1 << endl;
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
it should be written in c++ Your program should take numbers from the user until the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this exercise, write a complete Java program that reads integer numbers from the user until...

    In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...

  • using c++ write a program that reads numbers from the user until the user enters a...

    using c++ write a program that reads numbers from the user until the user enters a Sentinel. Use a Sentinel of -999. Ignore all negative numbers from the user input. Do the following: 1. Output the sum of all even numbers

  • Write a program that will loop ten times. In each iteration prompt user to enter an...

    Write a program that will loop ten times. In each iteration prompt user to enter an integer between -50&50. Print the input, keep a running sum of the inputs, and track the minimun and maximum numbers input. After the loop is complete, minimum number entered, maximum number entered, sum of all numberes entered, and average of all numbers entered. Format all output. Before running the loop, print the label "Input values: ". Within the loop, print value entered by user...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

  • In C++ 2. Write a program that allows the user to enter a series of positive...

    In C++ 2. Write a program that allows the user to enter a series of positive numbers between 1 and 100 and displays the smallest and largest of the numbers entered. The program should not store the numbers that were entered, only keep track of the smallest and largest ones. The program should continue accepting numbers until the value 0 is entered and then display the results. If a number out of range is entered, tell the user it is...

  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters...

    5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. ​ 1 largest = None 2 smallest = None 3 while True: 4...

  • Write a program that accepts numbers entered by the user until the user enters a zero....

    Write a program that accepts numbers entered by the user until the user enters a zero. The program then must display the largest value that is smaller than zero. This should be java program

  • I have to write a program in java which uses while loops. 1.prompt the user to...

    I have to write a program in java which uses while loops. 1.prompt the user to input two intergers: firstnum ans second numnumber. (first number must be smaller that the second number). 2. Output all the even numbers between first number and second number inclusive. 3. Output the sum of all the even number between first number and second number inclusive. 4 Output all the odd numbers between first number and second number inclusive. 5. Output the sum of all...

  • In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that...

    In Java #2 JAVA Write a program named salaryCalculator that accepts input from the user that represents an annual salary for employees. This program should all be written in the main driver program no additional classes are needed. Your program should do the following: Prompt the user for a salary continually until the user enters a sentinel value, a negative number. Keep two running totals the first is the total of all original salaries and the second is a total...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT