Thread: Determine Gross wage using class

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    8

    Determine Gross wage using class

    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.

    Code:
    #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;
    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    >> When I try to run it, it gives me this error

    What error? And why are you reading the input twice (once from main and then from set())?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    Code:
    #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;
    }
    Why do you read in "payRate" and "hours" in main and again in the "set" function? You don't need to read those values in main; just use the set function.
    IDE - Visual Studio 2005
    Windows XP Pro

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    72
    not to mention you can't just use them without initializing them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 01:03 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  4. Replies: 7
    Last Post: 05-26-2005, 10:48 AM