First declare an array that is large enough to hold at most 25floating point val
ID: 3615560 • Letter: F
Question
First declare an array that is large enough to hold at most 25floating point values.
You are to ask the user to enter a value in the range of 5 to25. The program should continue to ask the user to enter a valueuntil he successfully enters a value in this range. You're free touse the function we had in the notes to actually get the propervalue.
You are then to get the indicated number of values from the userand store them in the previously-defined array.
After you have gotten all the numbers from the user, you are tofind and display the sum and the average of all the values the userentered.
You are then to display the average of all the values the userentered that are greater than 100.0.
Finally, you are to display all the numbers the user entered,but only display three per line.
Here are two examples of how the output might appear:
How many values are you going to enter (5-25)? 30 Too many values; try again. How many values are you going to enter (5-25)? 2 Too few values; try again. How many values are you going to enter (5-25)? 8 Please enter value 1: 12.2 Please enter value 2: 7.6 Please enter value 3: -200.3 Please enter value 4: 140.7 Please enter value 5: 890.23 Please enter value 6: 67.78 Please enter value 7: 99.9 Please enter value 8: 100.1 The sum of the values is 1118.21 The average is 139.776 The average of the values > 100 is 377.01 12.2 7.6 -200.3 140.7 890.23 67.78 99.9 100.1
Explanation / Answer
#include<iostream.h> #include<conio.h>void main() { float *size; int num; cout<<"Enter a Number for Array"; cin>>num; if(num>25) cout<<"To Many Values: try again."; if(num<5) cout<<"To Few Values: try again"; if((num>=5)&&(num<=25)) size=new float [num];
float sum=0; float hsum=0; int hnum=0; float avg=0; for(int v=0;v<num;v++) { cout<<"Enter valueNo."<<(v+1)<<"="; cin>>*size; if(*size>100) { hsum=hsum+(*size); hnum++; } sum+=sum+(*size); size++; } avg=sum/num; cout<<"Sum of Values is"<<sum; cout<<" Average of valuesis"<<avg; cout<<" Sum of values >100is"<<hsum; cout<<" Average of values > 100 is"<<(hsum/hnum); getch(); }
Hope you got the solution of your problem...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.