Looping help!

so I have my code and it works fine but I need it to be able to run for an infinite amount of employees or 0 employees. After the function is called for the first employee it will ask for the employee type again but no matter the input it exits with code 0 and I can't figure out why. If someone could point me in the right direction that would be awesome, thanks! Also, i am wondering if I am passing by reference correctly?

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
95
96
97
98
99
100
101
102
103
104
105
#include "File.hpp"
#include <iostream>
using namespace std;


double Employeesal(double& x);
double Employeesal(double& wage, double& hr);





void employee_type (signed int& emp)
{
cout << "enter employee type(1 for hourly and 0 for salary or -1 to exit):" <<endl;
cin >> emp;
    
    
}
int main()
{
    
    double yearsal;
    double x;
    signed int emp;
    double hr;
    double wage;
    double hrsal;
    employee_type (emp);
  
    
    
    if (emp == 1){
        cout << "Enter hours worked this week:"<< endl;
        cin >> hr;
        cout << "Enter horly pay:"<< endl;
        cin >> wage;
        hrsal = Employeesal (hr,wage);
        
        cout << " The weekly pay is:"   << hrsal << endl;
       
    }
    
   else if ( emp == 0)
    {
       
       
        cout << "Enter yearly salary:" << endl;
        cin >> x;
        
        yearsal = Employeesal(x);
        
        cout << "The weekly gross salary is:" << yearsal << endl;
        
      
        
    }
    
    else if (emp == -1){
        return 0;
    }
   
    
    if (emp == 1 or 0)
    {
        employee_type(emp);
    }
  
    
}






double Employeesal(double& hr, double& wage)
{
    
    double hrsal;
    hrsal= hr * wage;
    
   
    return hrsal;
    
}



double Employeesal(double& x)
{
 
   
    

    int weeks =52;
    
    double sal = x / weeks;
    return sal;

   
    
   
    
}
You haven't put a loop in. If you want your code to loop, you need to put a loop in.

http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.