Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

My Program

Status
Not open for further replies.

gazflat33

Technical User
Nov 22, 2002
13
GB
PLease can anyone debug my program for me!:

#include <iostream.h>
#include <fstream.h>
#include <string.h>


const int MAX_SIZE = 20;
const int MAX = 10;

typedef char string[MAX_SIZE];

void mortgage(int mort_int[MAX],float mort_float[MAX],string mort_name[MAX]);

void loan(int loan_int[MAX],float loan_float[MAX],string loan_name[MAX]);

void savings(int save_int[MAX],float save_float[MAX],string save_name[MAX]);

void output(int mort_int[MAX],float mort_float[MAX],string mort_name[MAX],
int loan_int[MAX],float loan_float[MAX],string loan_name[MAX],
int save_int[MAX],float save_float[MAX],string save_name[MAX]);


void main()
{
mortgage(int mort_int[MAX],float mort_float[MAX],string mort_name[MAX]);
loan(int loan_int[MAX],float loan_float[MAX],string loan_name[MAX]);
savings(int save_int[MAX],float save_float[MAX],string save_name[MAX]);
output(int mort_int[MAX],string mort_name[MAX],int loan_int[MAX],
string loan_name[MAX],int save_int[MAX],string save_name[MAX]);

}


void mortgage(int mort_int[MAX],float mort_float[MAX],string mort_name[MAX])
{
float mort_ave=0;
float mort_tot = 0;
int counter = 0;
ifstream in_file;

in_file.open (&quot;mort.txt&quot;);
cout <<&quot;\n Mortgage info&quot;<<endl<<endl;
int j = 0;
in_file >> mort_name[j]>>mort_int[j]>>mort_float[j];
while (!in_file.eof())
{
cout << mort_name[j]<<&quot; &quot;<< mort_int[j] <<&quot; &quot;<< mort_float[j] <<endl;
j++;
in_file >> mort_name[j] >>mort_int[j]>>mort_float[j];
counter ++;
}
for (j = 0;j < MAX; ++j)
{
mort_tot = mort_tot + mort_float[j];
mort_ave = mort_tot / counter;
}
cout <<&quot;average is &quot;<<mort_ave<<endl;
cout <<&quot;maximum is &quot;<<mort_tot<<endl;

in_file.close();


}

void loan(int loan_int[MAX],float loan_float[MAX],string loan_name[MAX])
{
int k =0;
int counter =0;
float loan_tot;
float loan_ave;
ifstream in_file;
in_file.open (&quot;loan.txt&quot;);
cout <<&quot;\n loan info&quot;<<endl<<endl;
in_file >>loan_name[k]>>loan_int[k]>>loan_float[k];
while (!in_file.eof())
{
cout << loan_name[k]<<&quot; &quot;<< loan_int[k] <<&quot; &quot;<< loan_float[k] <<endl;
k++;
counter++;
in_file >> loan_name[k]>>loan_int[k]>>loan_float[k];
}
for (int j = 0;j < MAX; ++j)
{
loan_tot = loan_tot + loan_float[j];
loan_ave = loan_tot / counter;
}
cout <<&quot;average is &quot;<<loan_ave<<endl;
cout <<&quot;maximum is &quot;<<loan_tot<<endl;
in_file.close();

}

void savings(int save_int[MAX],float save_float[MAX],string save_name[MAX])
{
int counter =0;
float save_tot =0;
float save_ave =0;
ifstream in_file;
in_file.open (&quot;save.txt&quot;);
cout <<&quot;\n Savings info&quot;<<endl<<endl;
int i = 0;
in_file >> save_name>>save_int>>save_float;
while (!in_file.eof())
{
cout << save_name<<&quot; &quot;<< save_int <<&quot; &quot;<< save_float <<endl;
i++;
counter ++;
in_file >> save_name>>save_int>>save_float;
}
for (int j = 0;j < MAX; ++j)
{
save_tot = save_tot + save_float[j];
save_ave = save_tot / counter;
}
cout <<&quot;average is &quot;<<save_ave<<endl;
cout <<&quot;maximum is &quot;<<save_tot<<endl;
in_file.close();
}

void output(int mort_int[MAX],string mort_name[MAX],int loan_int[MAX],
string loan_name[MAX],int save_int[MAX],string save_name[MAX])
{
ofstream single_out_file;
ofstream joint_out_file;

single_out_file.open(&quot;1's.txt&quot;);
joint_out_file.open(&quot;2's.txt&quot;);

for (int j = 0;j < MAX; ++j)
{
if (mort_int[j] == 1)
single_out_file <<&quot;Mortgage &quot;<< mort_name[j] <<&quot; &quot; << mort_int[j] << endl;
if (loan_int[j] == 1)
single_out_file <<&quot;loan &quot; << loan_name[j] <<&quot; &quot; << loan_int[j] <<endl;
if (save_int[j] == 1)
single_out_file <<&quot;savings &quot;<< save_name[j] <<&quot; &quot; << save_int[j] <<endl;
if (mort_int[j] == 2)
joint_out_file <<&quot;Mortgage &quot;<< mort_name[j] <<&quot; &quot; << mort_int[j] <<endl;
if (loan_int[j] == 2)
joint_out_file <<&quot;loan &quot;<< loan_name[j] <<&quot; &quot; << loan_int[j] <<endl;
if (save_int[j] == 2)
joint_out_file <<&quot;savings &quot;<< save_name[j] <<&quot; &quot; << save_int[j] <<endl;
}
}
 
Sorry i forgot to mention that the errors i am getting are:

Error 24:Expression syntax in fuction main()
Error 25:Expression syntax in fuction main()
Error 26:Expression syntax in fuction main()

Thanks

Gaz
 
try this

main()
{

mortgage(mort_int[MAX],mort_float[MAX],mort_name[MAX]);
loan(loan_int[MAX],loan_float[MAX],loan_name[MAX]);
savings(save_int[MAX],save_float[MAX],save_name[MAX]);
output(mort_int[MAX],mort_name[MAX],loan_int[MAX],
loan_name[MAX],save_int[MAX],save_name[MAX]);
}

you don't redeclare the variable type in the function call, you simply insert the variable that you want to pass the function. make sure the variable you are passing in that place is the same type it expects. Make sure that you have declared these variables somewhere.
 
OK i done this wings (thanks for replying by the way) and i get these errors now:

Error 24:Undefined symbol 'mort_int' in function main()
Error 24:Undefined symbol 'mort_float' in function main()
Error 24:Undefined symbol 'mort_name' in function main()
Error 25:Undefined symbol 'loan_int' in function main()
Error 25:Undefined symbol 'laon_float' in function main()
Error 25:Undefined symbol 'loan_name' in function main()
Error 26:Undefined symbol 'save_int' in function main()Error 26:Undefined symbol 'save_float' in function main()Error 26:Undefined symbol 'save_name' in function main()
Error 28:Too few parameters in call to 'output(int*,float*,char*...in function main()

Any other ideas guys?
 
Gaz,

You need to declare all the symbols used in main() before they are used in the calls. That will get rid of the Error 26s.

Roy
 
ok heres how it looks now:

void main()
{
int mort_int;
float mort_float;
string mort_name;
int loan_int;
float loan_float;
string loan_name;
int save_int;
float save_float;
string save_name;

mortgage(mort_int[MAX],mort_float[MAX],mort_name[MAX]);
loan(loan_int[MAX],loan_float[MAX],loan_name[MAX]);
savings(save_int[MAX],save_float[MAX],save_name[MAX]);
output(mort_int[MAX],mort_name[MAX],loan_int[MAX],loan_name[MAX],
save_int[MAX],save_name[MAX]);

}

Error WIGAN1.CPP 34: Invalid indirection in function main()
Error WIGAN1.CPP 34: Invalid indirection in function main()
Error WIGAN1.CPP 34: Cannot convert 'int' to 'char ( *)[20]' in function main()
Error WIGAN1.CPP 34: Type mismatch in parameter 'mort_name' in call to 'mortgage(int *,float *,char ( *)[20])' in function main()
Error WIGAN1.CPP 35: Invalid indirection in function main()
Error WIGAN1.CPP 35: Invalid indirection in function main()
Error WIGAN1.CPP 35: Cannot convert 'int' to 'char ( *)[20]' in function main()
Error WIGAN1.CPP 35: Type mismatch in parameter 'loan_name' in call to 'loan(int *,float *,char ( *)[20])' in function main()
Error WIGAN1.CPP 36: Invalid indirection in function main()
Error WIGAN1.CPP 36: Invalid indirection in function main()
Error WIGAN1.CPP 36: Cannot convert 'int' to 'char ( *)[20]' in function main()
Error WIGAN1.CPP 36: Type mismatch in parameter 'save_name' in call to 'savings(int *,float *,char ( *)[20])' in function main()
Error WIGAN1.CPP 37: Invalid indirection in function main()
Error WIGAN1.CPP 37: Invalid indirection in function main()
Error WIGAN1.CPP 38: Invalid indirection in function main()
Error WIGAN1.CPP 38: Cannot convert 'int' to 'float *' in function main()
Error WIGAN1.CPP 38: Type mismatch in parameter 'mort_float' in call to 'output(int *,float *,char ( *)[20],int *,float *,char ( *)[20],int *,float *,char ( *)[20])' in function main()
Error WIGAN1.CPP 38: Cannot convert 'int' to 'int *' in function main()
Error WIGAN1.CPP 38: Type mismatch in parameter 'loan_int' in call to 'output(int *,float *,char ( *)[20],int *,float *,char ( *)[20],int *,float *,char ( *)[20])' in function main()
Error WIGAN1.CPP 38: Cannot convert 'int' to 'char ( *)[20]' in function main()
Error WIGAN1.CPP 38: Type mismatch in parameter 'loan_name' in call to 'output(int *,float *,char ( *)[20],int *,float *,char ( *)[20],int *,float *,char ( *)[20])' in function main()
Error WIGAN1.CPP 38: Too few parameters in call to 'output(int *,float *,char ( *)[20],int *,float *,char ( *)[20],int *,float *,char ( *)[20])' in function main()
Warning WIGAN1.CPP 40: 'save_name' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'save_float' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'save_int' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'loan_name' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'loan_float' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'loan_int' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'mort_name' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'mort_float' is declared but never used in function main()
Warning WIGAN1.CPP 40: 'mort_int' is declared but never used in function main()
Warning WIGAN1.CPP 93: Possible use of 'loan_tot' before definition in function loan(int *,float *,char ( *)[20])
 
your declaring single instances of variables instead of arrays, yet you use an array in your function?

int mort_int;

should be int mort_int[Max];

but you have not even declared max.

Without trying to be insulting, I suggest that you attempt a stripped down version of your program, with maybe only one function call until you get the hang of it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top