Here is the problem i Designed a program to collect blood from users after collecting the data i give them the output. one of the output is retrieved from outside function which is getTotalAmount but i am getting error: too few arguments to function 'float getTotalAmount'. code attached below :
class BloodDonator{
private:
string bloodtype ,name;
float amount ;
public:
void set_details(){
cout<<"Enter Name :";
cin>>name;
cout<<"Please select a blood type ...\n";
cout<<" Enter [1] for A positive\n";
cout<<" Enter [2] for A negative\n";
cout<<" Enter [3] for B positive\n";
cout<<" Enter [4] for B negative\n";
cout<<" Enter [5] for O positive\n";
cout<<"Enter [6] for O negative\n";
cout<<"Enter [7] for AB positive\n";
cout<<"Enter [8] for AB negative\n";
cin>>bloodtype;
cout<<"Enter Amount (ml) :";
cin>>amount;
};
float getAmount(){
return amount;
};
string getName(){
return name;
};
string getBloodType(){
return bloodtype;
};
getTotalAmount(float &amount);
string n(){return name;}
};
float getTotalAmount(BloodDonator *ps)
{
static float totalamount=0;
totalamount = totalamount + ps->getAmount();
return totalamount;
};
int main()
{
BloodDonator p1 ;
//float getTotalAmount();
//getTotalAmount();
for(int i=0;i<3 ;i++){
cout<<" Input Details\n";
cout<<"------------------------------\n";
p1.set_details();
//p1.getTotalAmount(*p1.getAmount());
cout<<"------------------------------\n";
cout<<" output Details\n";
cout<<"------------------------------\n";
cout<<"name :"<<p1.n()<<endl;
cout<<"blood type :"<<p1 .getBloodType()<<endl;
cout<<"Blood Amount :"<<p1.getAmount()<<endl;
cout<<"Total Amount of Blood Donated so far :\n"<<getTotalAmount()<<endl;//here is total amount of blood
}
return 0 ;
}
getTotalAmount
takes one parameter: BloodDonator*`. You're calling it with o parameters.getTotalAmount(float &amount);
taking a float reference. You later define a general functionfloat getTotalAmount(BloodDonator *ps)
taking a pointer toBloodDonator
and then you attempt to usecout ... <<getTotalAmount()
-- None of those match (or make much sense)