Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ language Create a program that will prompt the user to enter a random num

ID: 665115 • Letter: I

Question

In C++ language

Create a program that will prompt the user to enter a random number of values. You are to find the sum of the values user entered by the user and how many of these values were greater than 0 and how many of the values were less than or equal to zero. Use the random number generator to generate a number between 5 and 25 (including 5 and 25). Then use a loop to prompt the user to enter the generated number of values on at a time. Calculate the sum of the values the user entered and count how many of these values were greater than 0 and how many of the values were less than or equal to zero. Output the number of values entered, the sum, how many values were greater than 0 and how many values were less than or equal to zero.

Explanation / Answer

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
    srand (time(NULL));
    int arr[25];
    int n=rand()%21 +5;
    int sumi=0;
    int counterLess=0,counterMore=0;
    for(int i=0;i<n;i++)
    {
        cout<<"Enter a number: ";
        cin>>arr[i];
        sumi+=arr[i];
        if(arr[i]>0)
            counterMore+=1;
        else
            counterLess+=1;
    }
    cout<<"Total number of values entered: "<<n<<endl;
    cout<<"Sum of values: "<<sumi<<endl;
    cout<<"Count of numbers greater than zero: "<<counterMore<<endl;
    cout<<"Count of numbers less than equal to zero: "<<counterLess<<endl;
    return 0;
}