1

Recommended Answers

All 12 Replies

#include <iostream>
using namespace std;
class Gama
{
private:
	int n;
	int a;
public:
	double x,z;
	double Beta();
	Gama()
	{
		cout<<"\n Jepi vlerat e a,n,x: ";
		cin>>a>>n>>x;
	}
	int geta() {return a;}
	int getn() {return n;}

};

double Gama::Beta()
{
	int i,b,k;
	double p=1;
	for(i=1;i<=n;i++)
		p=p*k*i+b;
	return p;
}
int main()
{
	int b,k;
	cout<<" jepe vleren e b=";
	cin>>b;
	cout<<"jepe k=";
	cin>>k;
	Gama g;
	g.z=g.geta/b+3*g.Beta();
	cout<<"vlera e z:"<<g.z;
	cin.get();cin.get();
return 0;
};

what is wrong with it?

line 37: geta() is a function -- you need to add the ()

Don't simply post your code - ask a question!

Don't simply post your code - ask a question!

THE PROBLEM IS WITH THE b variable

Don't simply post your code - ask a question!

The variable k is being used without being intialized
what does this meen?

Don't simply post your code - ask a question!

The variable k is being used without being intialized
what does this meen?

The variable k is being used without being intialized
what does this meen?

Look at like 26: what is the value of variables b and k? Answer: their value is just some random number that happens to be in the memory location when the function started. You need to set b and k to some number before that loop starts.

Look at like 26: what is the value of variables b and k? Answer: their value is just some random number that happens to be in the memory location when the function started. You need to set b and k to some number before that loop starts.

cout<<" jepe vleren e b=";
cin>>b;
cout<<"jepe k=";
cin>>k;

but i have declared these variables in the main.

you are looking at the wrong line -- see line 26 in the code you posted above, which may or may not be the same line in your compiler.

The variables b and k declared on line 31 are not the same as the variables declared on line 23. If you want to use the variables declared in main() then you will have to pass them as parameters to Bata() function. double Gama::Beta(int b, int k) Another option is to make b and k members of the class.

you are looking at the wrong line -- see line 26 in the code you posted above, which may or may not be the same line in your compiler.

SO if i replace the code from line 22 to line 27 with this

int i,b=3,k=2;
double p=1;
for(i=1;i<=n;i++)
p=p*k*i+b;
return p;


Is it going to be OK, because it compiles fine, but i am not sure the result is correct.

you are looking at the wrong line -- see line 26 in the code you posted above, which may or may not be the same line in your compiler.

The variables b and k declared on line 31 are not the same as the variables declared on line 23. If you want to use the variables declared in main() then you will have to pass them as parameters to Bata() function. double Gama::Beta(int b, int k) Another option is to make b and k members of the class.

That is what i wanted to do, i want to use the same variables , but i don't know how to do it exactly

That is what i wanted to do, i want to use the same variables , but i don't know how to do it exactly

I just told you how. Add the two variables as parameters to the function then pass them on line 37, just like you would pass a variable to any other standard function. And don't forget to change the function declaration in the class iteself. Findlly, delete b and k on line 23.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.