I am trying to make a program that computes gross by using a class and three functions. When I try to run it, it gives me this error I think something is wrong with my set function and my int main function, any help would be appreciated, I think it has to do with template.

#include <iostream>
using namespace std;

double payRate;
int hours;

class Employee
{
 public:
 void set(double payRate, int hours);
 double pay();
 void display();

 private:
 int hours;
 double payRate;
 double Gross;
};

int main()
{
 Employee wage;
 cout << "What is the pay rate:";
 cin >> payRate;
 cout << "How many hours worked:";
 cin >> hours;
 wage.set(payRate, hours);
 wage.display();
}

void Employee::set(double payRate, int hours)
{
 cin >> payRate;
 cin >> hours;
}

double Employee::pay()
{
 return Gross= payRate* hours;
}

void Employee::display()
{
 cout << "The Gross wage is: " << Gross;
}
VernonDozier commented: Code tags on first post. +12
void Employee::set(double payRate, int hours)
{
 cin >> payRate;
 cin >> hours;
}

Change that to...

void Employee::set(double payRate, int hours)
{
  this->payRate = payRate;
  this->hours = hours;
}

I'm not guarranteeing that it works on every compiler, but I think it should. If you don't understand the code, let me know.

Also, move your globals

double payRate;
int hours;

into your main:

int main()
{
 double payRate;
 int hours;
 Employee wage;
 cout << "What is the pay rate:";
 cin >> payRate;
 cout << "How many hours worked:";
 cin >> hours;
 wage.set(payRate, hours);
 wage.display();
}

Thank you for using code tags!

void Employee::set(double payRate, int hours)
{
 cin >> payRate;
 cin >> hours;
}

It seems to me you should either have a set function that takes parameters but doesn't have cin statements, or a set function that has cin statements but takes no parameters, but having a set function that takes parameters AND immediately writes over those parameters with user input before doing anything with them doesn't make sense to me. If you are going to ask for input in main, don't do it the set function too.

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.