Rounding a value up or down in DOS promt C++

I am trying to write a simple payroll program however I am having trouble with the values not rounding properly. Please help.

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;
using std::cout ;
using std::cin ; 
using std::endl ;

//Global Declarations of Variables
double ihoursm = 0, ihourst = 0, ihoursw = 0, ihoursth =0, ihoursf = 0, ihourss = 0, ihourssu = 0, ohoursm= 0, 
ohourst = 0, ohoursw = 0, ohoursth =0, ohoursf = 0, ohourss = 0, ohourssu = 0, iwage = 0, mhours, net_pay,
thours, whours, thhours, fhours, shours, suhours, totalhours, federal, oasdi, medicare, state, retirement = 0;
int grosspay;
string cname ;


int main ()
{
	//Enter Employee Information
	
	cout << "\n\nEnter the employee name =" ;
	cin >> cname;
	cout << "\n\nEnter the time clocked in on Monday =" ;
	cin >> ihoursm;
	cout << "\n\nEnter the time clocked out on Monday =" ;
	cin >> ohoursm;
	cout << "\n\nEnter the time clocked in on Tuesday =" ;
	cin >> ihourst;
	cout << "\n\nEnter the time clocked out on Tuesday =" ;
	cin >> ohourst;
	cout << "\n\nEnter the time clocked in on Wednesday =" ;
	cin >> ihoursw;
	cout << "\n\nEnter the time clocked out on Wednesday =" ;
	cin >> ohoursw;
	cout << "\n\nEnter the time clocked in on Thursday =" ;
	cin >> ihoursth;
	cout << "\n\nEnter the time clocked out on Thursday =" ;
	cin >> ohoursth;
	cout << "\n\nEnter the time clocked in on Friday =" ;
	cin >> ihoursf;
	cout << "\n\nEnter the time clocked out on Friday =" ;
	cin >> ohoursf;
	cout << "\n\nEnter the time clocked in on Saturday =" ;
	cin >> ihourss;
	cout << "\n\nEnter the time clocked out on Saturday =" ;
	cin >> ohourss;
	cout << "\n\nEnter the time clocked in on Sunday =" ;
	cin >> ihourssu;
	cout << "\n\nEnter the time clocked out on Sunday =" ;
	cin >> ohourssu;
	cout << "\n\nEnter his or her hourly wage =" ;
	cin >> iwage;


	//Determine if hours are greater than 40
	
	{
		//Do Calculations

		float val = 0.00;
		float rounded_down = floorf(val * 100) / 100;
		float nearest = floorf(val * 100 + 0.5) / 100;
		float rounded_up = ceilf(val * 100) / 100;
				
		mhours =  (double) (ohoursm - ihoursm) ;
		thours =  (double) (ohourst - ihourst) ;
		whours =  (double) (ohoursw - ihoursw) ;
		thhours =  (double) (ohoursth - ihoursth) ;
		fhours =  (double) (ohoursf - ihoursf) ;
		shours =  (double) (ohourss - ihourss) ;
		suhours =  (double) (ohourssu - ihourssu) ;
		totalhours = (double) (mhours + thours + whours + thhours + fhours + shours + suhours) ;
		grosspay = (totalhours * iwage) ;
		federal = (grosspay * 0.04) ;
		oasdi = (grosspay * 0.035) ;
		medicare = (grosspay * 0.012) ;
		state = (grosspay * 0.038) ;
		retirement = (grosspay * 0.05);
		net_pay = (grosspay - federal - oasdi - medicare - state - retirement - 4.50 - 115.89 - 42.02 - 13.98					- 16.35);

	}
		{//Display Employee Details
				
			cout << "\n\n" ;
			cout << "Employee Name............=" <<cname<< endl ;
			cout << "Total Hours ...... =" <<totalhours<< endl ;
			cout << "Gross Pay.........="<<totalhours * iwage<< endl ;
			cout << "Net Pay...........="<<net_pay<< endl ;
		}//End of the Primary Statement


}//End of Int Main 

This is my output



Enter the employee name =Mike


Enter the time clocked in on Monday =8.00


Enter the time clocked out on Monday =20.00


Enter the time clocked in on Tuesday =8.00


Enter the time clocked out on Tuesday =20.00


Enter the time clocked in on Wednesday =8.00


Enter the time clocked out on Wednesday =17.00


Enter the time clocked in on Thursday =7.00


Enter the time clocked out on Thursday =17.00


Enter the time clocked in on Friday =7.00


Enter the time clocked out on Friday =17.00


Enter the time clocked in on Saturday =8.00


Enter the time clocked out on Saturday =16.27


Enter the time clocked in on Sunday =0


Enter the time clocked out on Sunday =0


Enter his or her hourly wage =12.50


Employee Name............=Mike
Total Hours ...... =61.27
Gross Pay.........=765.875
Net Pay...........=438.385
Press any key to continue . . .
You should implement these as functions:

1
2
3
4
float val = 0.00;
float rounded_down = floorf(val * 100) / 100;
float nearest = floorf(val * 100 + 0.5) / 100;
float rounded_up = ceilf(val * 100) / 100;


such as

1
2
3
4
5
float round_down(float val);

float nearest(float val);

float round_up(float val);


Right now, you're rounding "val" (0.00) three different ways, but you're not rounding any of your output.
Topic archived. No new replies allowed.