int getNum1();
int getNum2();
int getNum3();
int getNum4();
int sum();
int average();
int product();
int smallest();
int largest();
private:
int num1, num2, num3, num4;
};
#endif // NUMBERFUN_H
[code]
#include <iostream>
#include "numberfun.h"
using std::cin;
using std::cout;
using std::endl;
int main()
{
int val1, val2, val3, val4;
cout<< "Kindly enter 4 numbers: ";
cin>> val1>>val2>>val3>>val4 ;
NumberFun fish(val1, val2, val3, val4);
cout<< " Num1 has the value: " <<fish.getNum1() <<endl;
cout<< " Num2 has the value: " <<fish.getNum2() <<endl;
cout<< " Num3 has the value: " <<fish.getNum3() <<endl;
cout<< " Num4 has the value: " <<fish.getNum4() <<endl;
cout<< " The sum of the 4 numbers are: " <<fish.sum() <<endl;
cout<< " The average of the 4 numbers are: " <<fish.average() <<endl;
cout<< " The smallest of the 4 numbers are: "<<fish.smallest() <<endl;
cout<< " The largest of the 4 numbers are: "<<fish.largest() <<endl;
cout<< " The product of the 4 numbers are: "<<fish.product() <<endl;
cin.get();
cin.get();
return 0;
}
[code]
#include "numberfun.h"
using namespace std;
Not sure if this is what's causing the problem, but I would get rid of void setValues() . You already have your set functions to change the variables individually, so you don't need another function for all of them together.
And your constructor should look like this:
1 2 3 4 5 6 7 8 9 10 11
NumberFun::NumberFun (int val1,int val2,int val3,int val4)
{
num1 = val1;
num2 = val2;
num3 = val3;
num4 = val4;
}
//The constructor is "inside" the class, so it is able to access the private variables
//directly. You don't have to use the set functions here.