?yBooks My library > CS 010 home> 4.11 : ??4 LAB: Varied amount of input data E
ID: 3721333 • Letter: #
Question
?yBooks My library > CS 010 home> 4.11 : ??4 LAB: Varied amount of input data E zyBooks catalogHelp/FAQ 4.11 CH4 LAB: Varied amount of input data Statistics are often calculated varying amounts of input data. Write a program that takes any number of integers from 0-99 as input, and outputs the average and min. A negative integer ends the input and is not included in the statistics. When the input is 15 200 5-1, the output is 10 0. You can assume that at least one non-negative integer is input. ACTIVITY 4.11.1:CH4 LAB: Varied amount of input data 0/6 main.cpp Load default template... 1 #includeExplanation / Answer
#include <iostream>
using namespace std;
int main() {
int n,avg=0;
int count=0;
int min = 99;
cout<<"Enter the number(0-99) -1 to end : ";
do
{
cin>>n;
if(n== -1)
break;
avg = avg+n;
count++;
if(min > n)
min = n;
}while(n>=0);
cout<<" Average : "<<avg/count;
cout<<" Minimum : "<<min;
return 0;
}
Output:
Enter the number(0-99) -1 to end : 15 20 0 5 -1
Average : 10
Minimum : 0
Do ask if any doubt. Please upvote.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.