somebody helped me with this program but every time i run it.it ask me for the h
ID: 3618502 • Letter: S
Question
somebody helped me with this program but every time i run it.it ask me for the highest temp of the month and the lowest for all12 months and after i enter them on the black screen and pressenter the black screen disappears. i don"t know why can"t iget this program to run properly.if you can help me with this that be great.
#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 theyear is "<<averagehigh(temperatures, months); cout<<"the average low temp for theyear is "<<averagelow(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][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;
}
if you can help me with this that be great.
#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 theyear is "<<averagehigh(temperatures, months); cout<<"the average low temp for theyear is "<<averagelow(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][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;
}
#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 theyear is "<<averagehigh(temperatures, months); cout<<"the average low temp for theyear is "<<averagelow(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][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;
}
Explanation / Answer
please rate - thanks C++ runs in a DOS window. when the program exits, the windowcloses. so to prevent this we add a system("pause") #include 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); coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.