CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Determine Gross wage using class

  1. #1
    Join Date
    Apr 2009
    Posts
    4

    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
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: Determine Gross wage using class

    i revised your code:

    Code:
    #include <iostream>
    using namespace std;
    
    
    
    class Employee
    {
     public:
     void set(double payRate, int hours);
     void pay();
     void display();
    
     private:
     int hours;
     double payRate;
     double Gross;
    };
    
    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.pay();
     wage.display();
     
      system("pause");
        return 0;
     
    }
    
    void Employee::set(double xpayRate, int xhours)
    {
     payRate = xpayRate;
     hours = xhours;
    }
    
    void Employee::pay()
    {
    Gross= payRate* hours;
    }
    
    void Employee::display()
    {
     cout << "The Gross wage is: " << Gross << endl;
    }
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  3. #3
    Join Date
    Apr 2009
    Posts
    4

    Re: Determine Gross wage using class

    appreciate the help, I wasn't totally sure what to put in the set function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)