#include<iostream> #include <fstream> #include<cmath> using namespace std; void
ID: 3680844 • Letter: #
Question
#include<iostream>
#include <fstream>
#include<cmath>
using namespace std;
void input(int tempArray)
{
ifstream fin;
ofstream fout;
fin.open("input1.txt");
fout.open("output.txt");
int array[24];
for(int i=0; i<24; i++)
fin >> array[i];
}
int average(int array[24])
{
int avg=0;
for(int i=0; i<24; i++)
avg+= array[i];
return avg/24.0;
}
void table(int array[24])
{
cout<<endl;
cout << "Hour Temperature Difference from the Average ";
for(int i=0;i<24;i++)
cout<<i<<" "<<array[i]<<" "<<array[i]-average(array[24])<<endl;
}
int min(int array[24])
{
int min = array[0];
for(int i=1; i<24; i++)
{
if(array[i] < min)
min = array[i];
}
return min;
}
int max(int array[24])
{
int max = array[0];
for(int i=1; i<24; i++)
{
if(array[i] > max)
max = array[i];
}
return max;
}
void sort(int array[24])
{
int i,j;
for(i=0;i<24;i++)
{
for(j=0;j<23;j++)
{
if(array[j]>array[j+1])
array[j]=array[j]+array[j+1]-(array[j+1]=array[j]);
}
cout<<array[i]<<" ";
}
}
int main()
{
ifstream fin;
ofstream fout;
fin.open("input1.txt");
fout.open("output.txt");
int array[24];
input(array[24]);
cout << "The average is "<<average(array[24])<<endl<<endl;
table(array[24]);
cout << "The minimum temperature is "<< min(array[24])<< endl;
cout << "The maximum temperature is "<< max(array[24])<< endl;
cout << "Sorted Temperature ";
sort(array[24]);
system("PAUSE");
return 0;
}
I am writing this program for my C++ class and i am getting an error. The lines below are all giving me the same error. It keeps saying [Error] invalid conversion from 'int' to 'int*' [-fpermissive]. Could someone explain to me how to fix these lines.
1. cout<<i<<" "<<array[i]<<" "<<array[i]-average(array[24])<<endl;
2. cout << "The average is "<<average(array[24])<<endl<<endl;
3. table(array[24]);
4. cout << "The minimum temperature is "<< min(array[24])<< endl;
5. cout << "The maximum temperature is "<< max(array[24])<< endl;
6. sort(array[24]);
Explanation / Answer
1. cout<<i<<" "<<array[i]<<" "<<array[i]-average(array[24])<<endl;
If you want the output elements are from from array so use this code inside a for loop to access array values
2. cout << "The average is "<<average(array[24])<<endl<<endl;
here average function will return avg as the value so the code becomes
cout << "The average is "<<avg<<endl<<endl;
3. table(array[24]);
this function will have no return type, change void to int at the place of function defining
4. cout << "The minimum temperature is "<< min<< ends;
Inside int min(int array[24]) return min as the value
5. cout << "The maximum temperature is "<< max(array[24])<< endl;
I think it become
cout << "The maximum temperature is "<< max<< endl;
Because it return max as value.
6. sort(array[24]);
Change the return type at the place of function defining.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.