//final.cpp
//Creates an array with 2 players' batting avg
//Read in hits and atbats for each player
//1) one player get data in main
//2) other get data in battingavg function
//battingavg function figures out battingavg for both players
// and puts them in array (not hits & abats), print out array in function
#include <iostream> // Rose 309 611 Jack 250 689
//COMPILE ERROR???? G:\C++\HW\final.cpp In function `int main()':
#include <fstream.h>
#include <stdlib.h>
using namespace std;
void BattingAverage(int hits, int atbats, int count); //&????
float batavg[2];
int hits, atbats, count;
char name;
int main()
{
ifstream inbat;
ofstream outbat;
inbat.open("inbat.txt");
outbat.open("outbat.txt");
if ( inbat.fail() )
{
cout<<"Output file doesn't exist!";
}
for ( int count=0; count<2; count++ )
{
inbat.getline(name,5); //ERROR: 35 G:\C++\HW\final.cpp invalid conversion from `char' to `char*'
//32 G:\C++\HW\final.cpp initializing argument 1 of
// `std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]'
inbat>>hits>>atbats;
BattingAverage(hits, atbats, count); //calling function to do calc
}
system("PAUSE");
inbat.close();
return 0;
}
void BattingAverage(int hits, int atbats, int count)
{
batavg[count] = (float)hits/(float)atbats;
cout<<name<<"'s batting average is:"<<batavg[count]<<endl; //ios
}
<< moderator edit: added [code][/code] tags and fixed indentation >>
Thank you so much for your help