Problems with Employee Summary at the end not showing

I had everything working, and when I went to check it before I turned it in, something messed up and I can't get it to run the Employee Summary at the end. Can someone direct me to what part I am missing here? I also keep getting 3 warnings C$@$$ "=" conversion from double to float possible loss of data ? lines 99, 101, and 109?:

    // ConsoleApplication29.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <iomanip>

    using namespace std;

    //
    //CLASS DECLARATION SECTION
    //
    class EmployeeClass
     {
    public:
    void ImplementCalculations(string EmployeeName, int hours, double wage);
    void DisplayEmployInformation(void);
    void Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2, EmployeeClass Emp3);
    string EmployeeName ;
    int hours ;
    float wage ;
    float basepay ;
    int overtime_hours ;
    float overtime_pay ;
    float overtime_extra ;
    float iTotal_salaries ;
    float iIndividualSalary ;
    int iTotal_hours ;
    int iTotal_OvertimeHours ;
    };

    int main()
    {   system("cls"); 

    cout << "\nWelcome to the Employee Pay Center\n\n" ;

    EmployeeClass Emp1;
    EmployeeClass Emp2;
    EmployeeClass Emp3;


    cout << "Enter the first employee's name      = ";
    cin >> Emp1.EmployeeName;
    cout << "\nEnter the hours worked               = ";
    cin >> Emp1.hours;
    cout << "\nEnter their hourly wage         = ";
    cin >> Emp1.wage;
    cout << endl;

    cout << "Enter the second employee's name      = ";
    cin >> Emp2.EmployeeName;
    cout << "\nEnter the hours worked               = ";
    cin >> Emp2.hours;
    cout << "\nEnter their hourly wage         = ";
    cin >> Emp2.wage;
    cout << endl;

    cout << "Enter the third employee's name      = ";
    cin >> Emp3.EmployeeName;
    cout << "\nEnter the hours worked               = ";
    cin >> Emp3.hours;
    cout << "\nEnter their hourly wage         = ";
    cin >> Emp3.wage;


    cout << endl;
    Emp1.ImplementCalculations(Emp1.EmployeeName, Emp1.hours, Emp1.wage);
    Emp2.ImplementCalculations(Emp2.EmployeeName, Emp2.hours, Emp2.wage);
    Emp3.ImplementCalculations(Emp3.EmployeeName, Emp3.hours, Emp3.wage);


    system ("pause");
    return 0;


    //This section you will send all three objects to a function that will add up the the         following information:
    //- Total Employee Salaries 
    //- Total Employee Hours
    //- Total Overtime Hours

    //The format for this function is the following:
    //- Define a new object.
    //- Implement function call [objectname.functionname(object name 1, object name 2, object name 3)]


    } //End of Main Function


    void EmployeeClass::ImplementCalculations (string EmployeeName, int hours, double wage)    {
    //Initialize overtime variables
    overtime_hours=0;
    overtime_pay=0;
    overtime_extra=0;

    if (hours > 40) 
    {       

    basepay = 40 * wage;
    overtime_hours = hours - 40;
    overtime_pay = wage * 1.5;
    overtime_extra = overtime_hours * overtime_pay;
    iIndividualSalary = overtime_extra + basepay;

    }   // if (hours > 40)
    else
    {   

    basepay = hours * wage;
    iIndividualSalary = basepay;

    }   
    DisplayEmployInformation ();

    } //End of Primary Function

    void EmployeeClass::DisplayEmployInformation () 
    {
    // This function displays all the employee output information.

    cout << "\n\n";
    cout << "Employee Name ............. = " << EmployeeName << endl;
    cout << "Base Pay .................. = " << basepay << endl;
    cout << "Hours in Overtime ......... = " << overtime_hours << endl;
    cout << "Overtime Pay Amount......... = " << overtime_extra << endl;
    cout << "Total Pay ................. = " << iIndividualSalary << endl;

    } // END OF Display Employee Information

    void EmployeeClass::Addsomethingup (EmployeeClass Emp1, EmployeeClass Emp2,     EmployeeClass Emp3)
    {

   iTotal_salaries = 0;
   iTotal_hours = 0;
   iTotal_OvertimeHours = 0;
      for (int i = 0; i < 3; ++i )
     {
        cout << "\n\n";
        cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
        cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" << endl;
        cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
        cout << "%%%% Total Employee Salaries ..... =" << iTotal_salaries << endl;
        cout << "%%%% Total Employee Hours ........ =" << iTotal_hours << endl;
        cout << "%%%% Total Overtime Hours......... =" << iTotal_OvertimeHours << endl;
        cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
        cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
     }
        system("PAUSE");
        return;
     } // End of function

Answers


You never call Addsomethingup, so it won't ever print the summary. Converting a double to a float of course loses precision. Use either float or double for all of your variables consistently (i.e. don't mix those unless you have a good reason not to, which you probably don't here).


(1) I compiled/ran this under MSVC 2010 and didn't get the type warnings. However, the warning issues are likely because you are mixing types -- wage, basepay and overtime_pay are all type float, and you are doing calculations that use variables with type int (the literal 40 and hours) a - use 40f instead of 40 (uses a floating point constant instead of int) and b - use static_cast(hours) instead of just hours in those statements c - consider using type double instead of float - you get better precision with double than type float anyways.

and as Mornfall noted, you never call the AddSomethingUp member function.

The only references to that function are the prototype header in the class description and the actual code itself -- you don't invoke it anywhere.

You can build functional code 'till the cows come home, but unless you actually tell the program, somewhere, to run it, it won't get executed. You need to invoke it after you have processed the employee data and before you have executed the 'return' statement from main.

This was written using some version of Visual Studio the dead give-away for that are the following lines:

// ConsoleApplication29.cpp : Defines the entry point for the console application.`
//
#include "stdafx.h"

did you try running it under the debugger in order to se what code was invoked?


Need Your Help

SQL injections in Rails 4 issue

sql ruby-on-rails ruby sql-injection

I'm trying to learn about SQL injections and have tried to implement these, but when I put this code in my controller:

How can I use Sencha Touch 2 in a Rails 3 app?

android ruby-on-rails ruby-on-rails-3 sencha-touch sencha-touch-2

Sencha Touch 2 is a framework for writing web or native applications targeted towards mobile devices. See: http://www.sencha.com/products/touch/