Question: My source code is NOT WORKING C++ $ ./average How many numbers? 3 Enter Number 1 5 6 The average is 4 The numbers less
My source code is NOT WORKING C++
$ ./average How many numbers? 3 Enter Number 1 5 6 The average is 4 The numbers less than the average are -2.06623e-19 The numbers less than the average are 4.59163e-41 The numbers less than the average are 5.88117e-39
Why am I getting ridiculously tiny numbers?
// This program calculates the average of any number of numbers. // Using the for structure #include
#include int main() { int n; float sum, avg; sum = 0; std::cout << "How many numbers? "; std::cin >> n; int size= n; float array[size]; std::cout << "Enter Number" << std::endl; for (int j = 0; j std::cin >> array[n]; sum = sum + array[n]; } //end for
avg = (float) sum / n; std::cout << "The average is " << avg << std::endl;
for(int i = 0; i < size; i++) {
if(array[i]< avg){
std::cout << "The numbers less than the average are " << array[i] << " ";
}
} 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
