- #1
Joe_K
- 33
- 0
Homework Statement
I am not completely finished with the assignment, but I was trying to test to make sure that my functions "low" and "high" would in fact return the proper value (the lowest number in the array, and the highest number in the array, respectively). However, when I compile, I get an error "CANNOT CONVERT DOUBLE TO DOUBLE". Can anybody see the reason why I might be getting this error? I would very much appreciate any help! Thank you!
The file reads in data from the expenses.txt document, so I have included that file as an attachment as well.
As you can see, I have no finished coding all of my functions yet, but I am trying to find out why I am getting the compile error.
Homework Equations
The Attempt at a Solution
#include <iostream>
#include <iomanip>
#include <fstream>
const int NUM_MON = 12; // number of months
using namespace std;
//function prototypes
void buildArrays(double[], double[], double[]);
void printUtilityStat(string, double, int);
void getSumArray(double, double, double, double);
void printArray(string, double, int);
double mean(double, int);
double sum(double, int);
double low(double, int);
double high(double, int);
void sortArray(double, int);
double gas[NUM_MON];
double water[NUM_MON];
double electricity[NUM_MON];
int main()
{
buildArrays(gas,water,electricity);
for (int i=0; i<NUM_MON; i++)
{
cout<< gas<<endl;
}
cout<<endl<<endl<<"Lowest is "<<low(gas, NUM_MON);
cout<<endl<<endl<<"Highest is "<<high(gas, NUM_MON);
system ("pause");
return 0;
}
void buildArrays(double gas[], double electricity[], double water[])
{
ifstream inFile;
inFile.open("expenses.txt");
if (inFile.fail() )
{
cout<<"Unable to open expenses.txt file\n";
exit(1);
}
string temp;
int i;
inFile>> temp;
for (i=0; i<NUM_MON; i++)
{
inFile>> gas;
}
inFile>> temp;
for (i=0; i<NUM_MON; i++)
{
inFile>> electricity;
}
inFile>> temp;
for (i=0; i<NUM_MON; i++)
{
inFile>> water;
}
}
void printUtilityStat(string caption, double array[], int size)
{
}
void getSumArray(double gas[], double electricity[], double water[], double sums[])
{
}
void printArray(string caption, double array[], int size)
{
}
double mean(double array[], int size)
{
double sum=0,
result=0;
for (int i=0; i< NUM_MON; i++)
{
sum+= array;
return (sum)/ size;
}
}
double sum(double array[], int size)
{
}
double low(double array[], int size)
{
int min =array[0];
for (int i=0; i<size; i++)
{
if (array<min)
{
min=array;
}
return min;
}
double high(double array[], int size)
{
int max =array[0];
for (int i=0; i<size; i++)
{
if (array>max)
{
max=array;
}
return max;
}
void sortArray(double array[], int size)
{
}