Error: incompatible types in assignment....

I am having some trouble getting this program to open so I re did it according to some notes taken from another program I found and now it won't even compile! If anyone could possibly help with this situation and maybe if I am actually doing this correct that would be great!

Purpose of program(s) - to write one that will process information for an unknown number of household utilities expenses and have the other one open and read the newly created file.

p.s. I haven't done anything to the second program so if there are any problems with that one too, please let me know! THANKS IN ADVANCE FOR EVERYONE'S HELP!!!



Program PT.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

const int NUM_MON = 12;

struct utilityInfo
	{
	char utility[20];
	double monthlyExpenses[NUM_MON];
	};

int main()
{

ifstream inFile;
ofstream outFile;

inFile.open("expenses2.txt");

	if( inFile.fail() )
		  {
		  cout << "input file did not open";
		  exit(-1);
		  }

outFile.open( "binary_utilities", ios::binary );

	if( outFile.fail() )
		  {
		  cout << "output file did not open";
		  exit(-1);
		  }


char s[20];
utilityInfo read;
int i;

inFile.getline( s, 20 );

while( inFile )
	{
		strcpy(read.utility,s);
		
		for (i = 0; i < NUM_MON; i++)
			{
				 inFile.getline( s, 20 );
				 read.monthlyExpenses = atof(s);
			 }
		
	outFile.write( (char *) &read, sizeof(utilityInfo));
		
		  inFile.getline( s, 20 );
	}


inFile.close();
outFile.close();


cout << endl;
system("pause");

return 0;
}





Program PT.2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
const int NUM_MON = 12;
 
struct utilityInfo
	{
	char utility[20];
	double monthlyExpenses[NUM_MON];
	};
 
int main()
{

ifstream inFile2;
 
utilityInfo UtilitiesArray[20];
int numUtilities;
 
	inFile2.open( "binary_expenses", ios::binary );
		if( inFile2.fail() )
			  {
			  cout << "input file 2 did not open";
			  exit(-1);
			  }
	 
numUtilities = 0;
	 
	inFile2.read( (char *) &UtilitiesArray[numUtilities], sizeof(utilityInfo));
		 
		while( inFile2 )
			  {
			  numUtilities++;
			 
			  inFile2.read( (char *) &UtilitiesArray[numUtilities], sizeof(utilityInfo));
			  }
		 
	inFile2.close();
	 
		for( int sub = 0; sub < numUtilities; sub++ )
			  {
			  cout << UtilitiesArray[sub].utility << "\t" << UtilitiesArray[sub].monthlyExpenses[NUM_MON] << endl;
			   
			  }
 
inFile2.close();

cout << endl;
system("pause");
 
return 0;
}


I haven't written the second part of the code that will display the output (I am having some trouble writing that as well) but here is how it should look.


Output
Here is the output for this assignment.

*** gas ***
sum over 12 months: $1400.23        average:     $ 116.69
highest cost:       $ 207.14        lowest cost: $  52.55

*** electricity ***
sum over 12 months: $1149.10        average:     $  95.76
highest cost:       $ 188.32        lowest cost: $  50.90

*** water ***
sum over 12 months: $ 629.84        average:     $  52.49
highest cost:       $  78.33        lowest cost: $  40.56

*** cable ***
sum over 12 months: $1310.95        average:     $ 109.25
highest cost:       $ 152.64        lowest cost: $  46.93

*** phone ***
sum over 12 months: $ 957.65        average:     $  79.80
highest cost:       $  83.57        lowest cost: $  79.15


and now it won't even compile!


Please show us the compiler errors. It makes it much easier ...
Jikax (113) Apr 17, 2012 at 9:11am
and now it won't even compile!


Please show us the compiler errors. It makes it much easier ...


OOPS! Im sorry.........


cpp 51.error: incompatible types in assignment of 'double' to 'double [12]'

There were more but I fixed those. With this one tried redefining the array using the constant 12 instead of NUM_MON but it still does the same error. THANKS FOR THE RESPONSE TOO!!!!
Last edited on
Topic archived. No new replies allowed.