float fucntion in class

Hi guys: How are you.... I have a problem an dont know how to solve it,,, I used fucntions in classess, 2 fucntions, one is for addition and other is for percentage, the add function is working,, while the float function where i stucked and dont have any idea what to do,, If anybody please help me and solve the problem in an easy way please... I want to calculate the percentage for the addition of above marks
below is the code:

#include <iostream>

using namespace std;
class khan{
public:
void print(){
cout<<"welcome to the online Addition System!!!" <<"\n" << endl;
}
int add(int x, int y, int z){
a = x+y+z;
return a;
}
float percentage(float per=0.0){
per = a*100.0/300.0;
return per;

}
private:
int a;
int total = 300.0;

};

int main()
{
khan kk;
kk.print();
int a,b,c;
cout<<"Enter Value for Maths" <<endl;
cin>> a;
cout<<"Enter Value for Science" <<endl;
cin>>b;
cout<<"Enter Value for English" <<endl;
cin>> c;
khan k;
k.add(a,b,c);
cout << k.add(a,b,c) << endl;

return 0;
}
First, you could use code tags.

Second, you say that percentage() "is not working" and "is stuck". In what way does it "not work"?
Try the following

float percentage()
{
float per = a * 100.0f/total;
return per;
}
Last edited on
Topic archived. No new replies allowed.