-1 IND

Jun 6, 2013 at 8:55pm
I am getting -1 IND for my output. I can't figure out what I did wrong. I am trying to calculate the batting average of a baseball player.

//main
#include <iostream>
#include <iomanip>
#include "player.h"
using namespace std;

int main()
{
player myPLayer("Louie","Panthers", 70, 185, 20);
int hit;
int N;
cout << "Enter Number of at-bats? ";
cin >> N;

int hits=0;
for (int i = 0; i < N; i++) {
cout << "Hit? (y/n) : y=1 n=0 " << endl;
cin >> hit;
if (hit==1){hits++;}
}


myPLayer.AddBattingData(N,hits);

myPLayer.getProfile();

return 0;
}


//player.cpp
#include "player.h"

player::player(string name, string team, int height, int weight, int age)
{
mAge=age;
mName=name;
mHeight=height;
mWeight=weight;
mTeam=team;
mBattingAverage=0.0;
mN=0;
mHits=0;

}

void player::AddBattingData(int N, int hits)
{
mBattingAverage = (double)mHits/mN;

}


void player::getProfile()
{
cout << mName << " is " << mAge << " years old " << "And is " << mHeight << "inches tall and weighs ";
cout << mWeight << " lbs. And plays with " << mTeam << endl;
cout << mName <<"'s batting average was " << mBattingAverage;
}

//player.h
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class player
{
public:
player(string name, string team, int height, int weight, int age);
int battingAverage;
void getProfile();
void AddBattingData(int N, int hits);

private:
int mAge;
int mWeight;
int mHeight;
string mName;
string mTeam;
double mBattingAverage;
int mN;
int mHits;

};
Jun 6, 2013 at 9:15pm
1
2
3
4
void player::AddBattingData(int N, int hits)
{
    mBattingAverage = (double)mHits/mN;
}


Neither N nor hits are used. So why does the function take them as parameters?
Jun 6, 2013 at 9:36pm
You're saying this should have been mN and mHits for the parameters?
Jun 6, 2013 at 9:39pm
Thank You! You're a life saver.
Jun 6, 2013 at 9:39pm
I'm saying you're not using the parameters fed to the function. And then I'm asking what you have parameters for if you're not going to use them.
Topic archived. No new replies allowed.