If/else statement wont work

I am having trouble getting my if and else statement to work. The program is a simple payroll calculator but when I try to put an else statement after my if statement the compiler tells me that it cant find an if statement to accompany the else statement. So I tried making 2 if statements with the appropriate conditions (or so I think) and the program prints out the information from both if statements. I could really use some help figuring this out. (FYI I use Visual Studio for my compiler if that makes any difference)

Heres the program:

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
  #include "stdafx.h"
#include <iostream>
using std::cout;using std::endl;
using std::cin;



int main()
{
   int n, etc, hw, hp, rp = 0, ot, otp, tp;
   
   cout<<"Enter the Employees Hourly Pay"<<endl;
	
			cin>>hp;
   
		while (hp<7.15 || hp>31)
		{     
			cout<<"Amount entered exceeds company pay scale."<<endl;
			
			cout<<"Enter the Employees Hourly Pay"<<endl;
	
			cin>>hp;
		}		//end while
		cout<<"Enter the number of hours worked for the week."<<endl;

			cin>>hw;

		while (hw<.01 || hw>80)
		{
			cout<<"Amount entered exceeds company work hour standards"<<endl;
			
			cout<<"Enter the number of hours worked for the week"<<endl;

			cin>>hw;
		}		//end while

	if (hw > 40)
	   rp= 40 * hp;					// regular pay = 40 hours x hourly pay

	   ot= hw - 40;					//overtime = hours worked - 40
			
	   otp= ot * (hp * 1.5);		//overtime pay = overtime x (hourly pay x 1.5)

	   tp= otp + rp;				//total pay = overtime pay + regular pay

	   cout<<"Hours Worked"<<endl;
	   cout<<hw<<endl;
	   cout<<endl;
	   cout<<"Regular Pay"<<endl;
	   cout<<rp<<endl;
	   cout<<endl;
	   cout<<"Overtime Pay"<<endl;
	   cout<<otp<<endl;
	   cout<<endl;
	   cout<<"Total Pay"<<endl;
	   cout<<tp<<endl;

	if (hw <= 40)

		rp= hw * hp;			// regular pay = 40 hours x hourly pay

		tp=rp;				//total pay = regular pay



	   cout<<"Hours Worked"<<endl;			
	   cout<<hw<<endl;
	   cout<<endl;
	   cout<<"Regular Pay"<<endl;
	   cout<<rp<<endl;
	   cout<<"Total Pay"<<endl;
	   cout<<tp<<endl;
							cout<<endl;
		
		cout<< "To calculate another payroll enter the Type Code"<<endl;
		cout<<"Otherwise type -1 press enter and then type any   character to exit program"<< endl; 

cin>> etc;
   cin >> n;
}
You need to put braces { } around the block of statements to be controlled by the if/else. Without them, only the very first statement after the if are dependent upon it.
That did the trick!! Thanks so much!
Topic archived. No new replies allowed.