# Passing pointers to functions

Discussion in 'C' started by thebath, May 12, 2008.

1. ### thebathNew Member

Joined:
May 12, 2008
Messages:
2
0
Trophy Points:
0
Prewarning: The Gwin commands are the graphics window we use

Hey, so i have to, create a function called WeightLoss. This function will take as its ONLY
parameter a POINTER to a Patient. The purpose of thefunction is as follows:
If the Patient passed in is male, the function will reduce the Patient's weight by 10%.
If the Patient passed in is female, the function will reduce the Patient's weight by 20%
Code:
```#include "stdafx.h"
#include "gwin.h"
#include <fstream>
#include <iostream>

using namespace std;
const int MAXPATIENTS = 10;
const int sex=2;
double	bmi[MAXPATIENTS][sex];
double*p=&bmi[MAXPATIENTS][sex];//Problems

struct patient
{
int ID;
double Weight;
double Height;
bool IsMale;
};
double weightLoss (double *p);//Problems line 28

int main()
{

patient dieters[MAXPATIENTS];
int i=0;
ifstream details("Dieters.txt");
Gwin.clear();
Gwin.writeText(10,0,"ID     BMI:");
while (i<10)
{
details>>dieters[i].ID>>dieters[i].Weight>>dieters[i].Height>>dieters[i].IsMale;
bmi[i]=dieters[i].Weight/(dieters[i].Height*dieters[i].Height);
bmi[i]=dieters[i].IsMale;
bmi[i]=weightLoss(bmi[i]);//Problems
if (bmi[i]>22&&dieters[i].IsMale)
{
Gwin.writeInt(0,15*i, dieters[i].ID);

Gwin.writeDouble(40,15*i, bmi[i]);

}
else if(bmi[i]>25&&!dieters[i].IsMale)
{
Gwin.writeInt(0,15*i, dieters[i].ID);

Gwin.writeDouble(40,15*i, bmi[i]);

}
i++;
}

Keyboard.getch();

return 0;
}
int weightLoss(double *p)//Problems
{
int j=j+1;
bool male;
if (bmi[j]=male)
{

bmi [j]=bmi[j]*0.9;
}
else if(bmi[j]!=male)
{
bmi[j]=bmi[j]*0.8;
}
return bmi;
}```

cpp(43) : error C2664: 'weightLoss' : cannot convert parameter 1 from 'double' to 'double *'
cpp(66) : error C2556: 'int weightLoss(double *)' : overloaded function differs only by return type from 'double weightLoss(double *)'
cpp(28) : see declaration of 'weightLoss'
cpp(66) : error C2371: 'weightLoss' : redefinition; different basic types
(74) : warning C4805: '!=' : unsafe mix of type 'double' and type 'bool' in operation

Joined:
May 12, 2008
Messages:
2