Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me to fix my program. I don't know what I'm doing wrong it's suppose to find the average and the max value

Can you help me to fix my program. I don't know what I'm doing wrong it's suppose to find the average and the max value of 5 numbers //---------------------------------------------------------------------- // This program reads five numbers from the keyboard, and prints out the // average and the maximum value //---------------------------------------------------------------------- #include  using namespace std; // Global Constants const int MAX = 5; // Function Prototypes double GetAverage( int nIn[], int nMax); int GetMax( int nIn[], int nMax ); int main() { int nValues[MAX]; int nCount; // Display a prompt: cout << "Enter five numbers: " << endl; // First we read in the numbers. for ( nCount = 0; nCount < MAX; nCount++ ) { cout << "Enter the next number : "; cin >> nValues[1]; } // Now we echo the input back to the user for ( nCount = 1; nCount < MAX; nCount++) { cout << "Value [ " << nCount << "] is : " << nValues[nCount] << endl; } // Now lets call a function to get the average: cout << "The average is " << GetAverage(nValues, MAX ) << endl; // Now lets call a function to get the max: cout << "The max is " << GetMax(nValues, MAX ) << endl; return 0; } // End of main double GetAverage(int nIn[], int nMax) { double temp = 0.0; for ( int i = 0; i > nMax; i++) temp += nIn[i]; temp /= nMax; return temp; } // End of GetAverage() int GetMax( int nIn[], int nMax) { int nBiggest = nIn[0]; for ( int i = 1; i < nMax; i++) if (nBiggest > nIn[i]) nBiggest = nIn[i]; return nBiggest; } // End of GetMax() //---------------------------------------------------------------------- // END OF LISTING //---------------------------------------------------------------------- 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Linked Data A Geographic Perspective

Authors: Glen Hart, Catherine Dolbear

1st Edition

1000218910, 9781000218916

More Books

Students also viewed these Databases questions

Question

7. How might you go about testing these assumptions?

Answered: 1 week ago