if statement with math?

Trying to do use if statement to subtract 35 from the totalNet. not sure if i am using it right. I apologize for the messiness. Feedback on how the set up would be appreciated.

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
#include "stdafx.h"
#include<iostream>
#include"string"
#include<cmath>
using namespace std;


int main()
{
	double hourlyRate(16.78);
	double overTime(1 + .5);
	double socialSec(.06);
	double federalIncome(.14);
	double incomeTax(.5);
	int unionDues(10);
		int healthInsurance(35);
		double totalNet;
		int hoursWorked;

		
		

			cout << "How many hours did you work this week? ";
	cin >>hoursWorked;
	


	int numDependents;
	cout<< "How many dependents do you have? ";
	cin >> numDependents;
		
	if (numDependents > 3)
	{
		(totalNet - 35);
	};
	

		double grossPay;
		grossPay = (hoursWorked*hourlyRate);
		
		cout << "Your total gross pay is " << grossPay;
		
		
		
	    
		
		








		totalNet = (hoursWorked*hourlyRate) - socialSec - federalIncome - incomeTax - unionDues;
		cout << "Your total net take home pay is " << totalNet;






		system("pause");
return 0;
}
You need to do either

Totalnets -= 35;

Or

Totalnets = Totalnets - 35;
Note: the semicolon on line 35 in unnecessary.

A more serious issue. Lets assume you fix the line 34 and there are many dependents.
You code will do:
1
2
3
double foo; // uninitialized, undefined value
foo -= 35; // if you take of something, you still don't know what you have
foo = 42; // No matter what you had, the foo is now 42 

I.e. your line 56 overwrites the value of totalNet.

Consider:
1
2
3
4
5
double dedu = 0;
if ( cond ) {
  dedu = 35;
}
double totalNet = 42 - dedu;

There is operator ? : too:
1
2
double dedu =  ( cond ) ? 35 : 0 ;
double totalNet = 42 - dedu;

Topic archived. No new replies allowed.