Help w/ Error Message

I wrote this small employee bonus calculation program (pretty easy), but I am getting an error message "(39) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data"

The error message seems to be happening when I use the = sign to determing the bonus calculation.

Any suggestions would be greatly appreciated, as I am about to pull my hair out!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
 
 
using std::cout;
using std::cin;
using std::endl;
 
int main()
{

// variable description     
     int     perFactor;          //  Employee’s performance factor
     int     yrsService;         //  Employee’s years of service
     int     empBonus;           //  Employee’s bonus percentage  
     int     empSalary;          //  Employee's salary 
 

cout <<endl <<  "Enter employees performance factor (1-10):";        
{
cin  >> perFactor;        // Read Performance Factor
}         
cout <<endl << "Enter employees years of service (0-60):";
{
cin  >> yrsService;       // Read employee's year(s) of service
}
cout <<endl <<  "Enter employees annual salary:";        
{
cin  >> empSalary;        // Read employee salary
}
  
if (yrsService < 0 && yrsService > 60)
{
cout << "Error: The years of service must be between 0 and 60.";
cout << "Try Again...\n\n";
}

if (perFactor < 5)
{
cout <<"The employee is not entitled to a bonus";
}

if (perFactor < 5 && yrsService < 5)
{
empBonus = empSalary *.01;
cout <<"Employee gets a .01% bonus, which calculates to: " << empBonus << endl;
}
if (perFactor < 5 && yrsService > 5)
{
empBonus = empSalary *.02;
cout <<"Employee gets a .02% bonus, which calculates to: " << empBonus << endl;
}
			

return 0;
}
You declared empBonus as an int, right? However, you multiply empSalary by a double (.01), making the result a double. You then try to assign that result to an int. This can cause data loss, such as 42.99 turning into 42 because int doesn't have decimals. You should turn your variables into double if you want to do this.
Awesome! Will do!! Thanks for the help!
Topic archived. No new replies allowed.