Aug 7, 2011 at 7:15am UTC
i need help in figuring out how to find the average interest of type u
[u] Text file[/u]
1111 p 50000.00 4.50
1112 e 35000.00 5.00
1113 u 45000.00 2.50
1114 p 25000.00 6.00
1115 u 20000.00 3.50
1116 u 57999.00 4.00
program file
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
#include<fstream>
int RD(int AC[],string type[],double amount[],double rate[],double interest[]);
double AI(double interest[],int size);
void PR(int AC[],string type[],double amount[],double rate[],double interest[],double average,int size);
void BA(double interest[],double average,int size);
int main()
{
const int MAX=50;
int AC[MAX];
string type[MAX];
double amount[MAX];
double rate[MAX];
double interest[MAX];
int size;
double average;
size=RD(AC,type,amount,rate,interest);
average=AI(interest,size);
PR(AC,type,amount,rate,interest,average,size);
BA(interest,average,size);
return 0;
}
int RD(int AC[],string type[],double amount[],double rate[],double interest[])
{
int i=0;
ifstream inFile;
inFile.open("invest.txt");
if(!inFile)
cout<<"Unable to open file"<<endl;
else
{
while (!inFile.eof())
{
inFile>>AC[i]>>type[i]>>amount[i]>>rate[i];
interest[i]=rate[i]/100*amount[i];
i++;
}
}
return i;
}
double AI(double interest[],int size)
{
double sum=0,average;
for (int i=0;i<size;i++)
sum+=interest[i];
average=sum/size;
return average;
}
void PR(int AC[],string type[],double amount[],double rate[],double interest[],double average,int size)
{
cout<<left<<fixed<<setprecision(2);
cout<<setw(15)<<"AC Number"<<setw(15)<<"Type"<<setw(20)<<"Amount($)"<<setw(15)<<"Rate(%)"<<"Interest($)"<<endl;
for (int i=0;i<size;i++)
cout<<setw(15)<<AC[i]<<setw(15)<<type[i]<<setw(20)<<amount[i]<<setw(15)<<rate[i]<<interest[i]<<endl;
}
void BA(double interest[],double average,int size)
{
}
Aug 7, 2011 at 8:22am UTC
Put your code in [cod e][/code] tags.
Express your problems. Do you only not know how to separate 'u' values from all others, or do you have problems parsing the whole thing?