Question: C++ Programming: My own source code is NOT WORKING exactly like the problem statement wants me to. $ clang++ average. cpp -o average $ ./average
C++ Programming: My own source code is NOT WORKING exactly like the problem statement wants me to.
$ clang++ average.cpp -o average $ ./average How many numbers? 3 Enter Number 2 1.5 4 The average is 2.5 The numbers less than the average are 0 [dmera@localhost lab1]$ clang++ average.cpp -o average [dmera@localhost lab1]$ ./average How many numbers? 3 Enter Number 2 1.5 4 The average is 2.5 The numbers less than the average are 0
This final checkpoint, however, requires the use of arrays to store values for later use. For Checkpoint 3, write a new program that reads a sequence of floats into an array, computes and prints the average, and then outputs all of the original numbers (in any order) that are less than the average. The first value input will be an integer giving the number of values in the sequence. The remaining input will be the values. You may assume there are at most 100 values. You do not need to write a separate function you may keep all of the code in the main function. As an example, given the input: 3 2.0 1.5 4.0 the program should output the the average value 2.5, and also print 2.0 and 1.5 because they are less than than 2.5. Given this larger input dataset: 15 40.2 9.4 -2.5 26.1 37.1 44.3 56.8 11.5 17.8 39.9 42.2 -1.7 89.2 65.1 27.1 the program should output the average 33.5 and also print the 7 values less than the average: 9.4 -2.5 26.1 11.5 17.8 -1.7 27.1
// This program calculates the average of any number of numbers. // Using the for structure #include
avg = sum / n; cout << "The average is " << avg << endl; float less_than_Ave[size]; int count = 0; int i =0; while(i < n){
if(array[i]< avg){ less_than_Ave[count]= array[i]; count = count +1; i = i +1; } } cout << "The numbers less than the average are " << less_than_Ave[size] << endl; return 0; //successful termination
}//end main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
