Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can any one tell me what i did wrong because i can\"t get thisprogram to run tha

ID: 3618466 • Letter: C

Question

can any one tell me what i did wrong because i can"t get thisprogram to run thanks
#include <cstdlib> #include <iostream>
using namespace std; const int months=12; void getdata (double [][2], int); double averagehigh(double [][2], int); double averagelow(double [][2], int); int indexhightemp(double[][2], int); int indexlowtemp(double[][2], int); int main() { double temperatures[months][2]; getdata(temperatures, months); cout<<"the average high temp for the year is"<<avergehigh(temperatures, months); cout<<"the average low temp for the year is"<<avergelow(temperatures, months);    return 0; } void getdata(double t[][2], int m) {    for (int i=0; i<m; i++)    {    cout<<"enter thehighest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    cout<<"enter thelowest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    }    } double avergehigh(double t[][2],int m) {    double sum=0;    for(int i=0; i<m; i++)    sum+= t[i][0];    return(sum/m);    } double avergelow(double t[][2],int m) {    double sum=0;    for(int i=0; i<m; i++)    sum+= t[i][1];    return(sum/m);    } int indexhightemp(double t[][2], int m) {    int ind=0;    double highest=t[0][0];    for(int i=1; i<m; i++)    if(t[i][0]>hightest)    {    highest=t[i][0];    ind=i;    }    return ind; } int indexlowtemp(double t[][2], int m) {    int ind=0;    double lowest=t[0][1];    for(int i=1; i<m; i++)    if(t[i][0]>lowest)    {    lowest=t[i][1];    ind=i;    }    return ind; }
#include <cstdlib> #include <iostream>
using namespace std; const int months=12; void getdata (double [][2], int); double averagehigh(double [][2], int); double averagelow(double [][2], int); int indexhightemp(double[][2], int); int indexlowtemp(double[][2], int); int main() { double temperatures[months][2]; getdata(temperatures, months); cout<<"the average high temp for the year is"<<avergehigh(temperatures, months); cout<<"the average low temp for the year is"<<avergelow(temperatures, months);    return 0; } void getdata(double t[][2], int m) {    for (int i=0; i<m; i++)    {    cout<<"enter thehighest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    cout<<"enter thelowest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    }    } double avergehigh(double t[][2],int m) {    double sum=0;    for(int i=0; i<m; i++)    sum+= t[i][0];    return(sum/m);    } double avergelow(double t[][2],int m) {    double sum=0;    for(int i=0; i<m; i++)    sum+= t[i][1];    return(sum/m);    } int indexhightemp(double t[][2], int m) {    int ind=0;    double highest=t[0][0];    for(int i=1; i<m; i++)    if(t[i][0]>hightest)    {    highest=t[i][0];    ind=i;    }    return ind; } int indexlowtemp(double t[][2], int m) {    int ind=0;    double lowest=t[0][1];    for(int i=1; i<m; i++)    if(t[i][0]>lowest)    {    lowest=t[i][1];    ind=i;    }    return ind; } #include <cstdlib> #include <iostream>
using namespace std; const int months=12; void getdata (double [][2], int); double averagehigh(double [][2], int); double averagelow(double [][2], int); int indexhightemp(double[][2], int); int indexlowtemp(double[][2], int); int main() { double temperatures[months][2]; getdata(temperatures, months); cout<<"the average high temp for the year is"<<avergehigh(temperatures, months); cout<<"the average low temp for the year is"<<avergelow(temperatures, months);    return 0; } void getdata(double t[][2], int m) {    for (int i=0; i<m; i++)    {    cout<<"enter thehighest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    cout<<"enter thelowest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    }    } double avergehigh(double t[][2],int m) {    double sum=0;    for(int i=0; i<m; i++)    sum+= t[i][0];    return(sum/m);    } double avergelow(double t[][2],int m) {    double sum=0;    for(int i=0; i<m; i++)    sum+= t[i][1];    return(sum/m);    } int indexhightemp(double t[][2], int m) {    int ind=0;    double highest=t[0][0];    for(int i=1; i<m; i++)    if(t[i][0]>hightest)    {    highest=t[i][0];    ind=i;    }    return ind; } int indexlowtemp(double t[][2], int m) {    int ind=0;    double lowest=t[0][1];    for(int i=1; i<m; i++)    if(t[i][0]>lowest)    {    lowest=t[i][1];    ind=i;    }    return ind; }

Explanation / Answer

Your getData method is having some problem...

both the variables are reading into first element only....
thats why you are getting the error while calculating lowaverage temperature.
void getdata(double t[][2], int m) {    for (int i=0; i<m; i++)    {    cout<<"enter thehighest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    cout<<"enter thelowest temp for the month"<<(i+1)<<" : ";    cin>>t[i][0];    }    }

here is the corrected code:
#include <iostream.h>

const int months=12;
void getdata (double [][2], int);
double averagehigh(double [][2], int);
double averagelow(double [][2], int);
int indexhightemp(double[][2], int);
int indexlowtemp(double[][2], int);

int main()
{
    double temperatures[months][2];
    getdata(temperatures, months);
    cout<<"the average high temp for the yearis "<<averagehigh(temperatures, months);
    cout<<"the average low temp for the yearis "<<averagelow(temperatures, months);
    return 0;
}

void getdata(double t[][2], int m)
{
     for (int i=0; i<m; i++)
     {
         cout<<"enterthe highest temp for the month"<<(i+1)<<" : ";
        cin>>t[i][0];
         cout<<"enterthe lowest temp for the month"<<(i+1)<<" : ";
        cin>>t[i][1];
     }
}

double averagehigh(double t[][2],int m)
{
     double sum=0;
     for(int i=0; i<m; i++)
    {
        sum+= t[i][0];
    }
     return(sum/(double)m);
}

double averagelow(double t[][2],int m)
{
    double sum=0;
    for(int i=0; i<m; i++)
    {
        sum+= t[i][1];
    }
    return(sum/(double)m);
}

int indexhightemp(double t[][2], int m)
{
    int ind=0;
    double highest=t[0][0];
    for(int i=1; i<m; i++)
    if(t[i][0]>highest)
    {
      highest=t[i][0];
      ind=i;
    }
    return ind;
}

int indexlowtemp(double t[][2], int m)
{
    int ind=0;
    double lowest=t[0][1];
    for(int i=1; i<m; i++)
    if(t[i][0]>lowest)
    {
       lowest=t[i][1];
        ind=i;
    }
   return ind;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote