To Loop

So my assignment is to make this program run as many times as the user wants, then create a file with multiple outputs.

With my research I was able to deduce that I need to use the do loop. Even then from my online research I'm not really getting anything clear. I tried adding do while but it only seemed to skip questions and not even give me an output. I know where is x>=1 stuff but I can't see how I could implement that into my coding. There must be a simpler way of doing that I just haven't seen.

Long story short, user enters input, gives output, console asks if user wants to enter another set of input, gives output, send all outputs to one file.

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 <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <cstdlib>
#include <utility>
using namespace std;
//************************ main ********************************
int main()
{
                                     
int                              class_id;                     
double                           employeeid,
                                 hrs_worked,
                                 ot_hours,
                                 total_pay,
                                 ot_pay,
                                 reg_rate,
                                 reg_pay;                  
char                             name[30],
                                 redo;        
                                                  
                                                  //input section section                                         
                                           

cout << "The Employee's Name: ";
cin >> ws;
cin.getline(name,(sizeof(name)-1));

cout << "The Employee's Id. Number: ";
cin >> employeeid; 

cout << "The Employee's Job Classification Number: ";
cin >> class_id;

switch (class_id)
{
case 1:    reg_rate = 5.00;
             break;
case 2:    reg_rate = 6.00;
             break;
case 3:    reg_rate = 9.00;
             break;
case 4:    reg_rate = 12.00;
             break;
default:   reg_rate = 5.00;
           break;           
}

cout << "The Number of Hours Worked. ";
cin >> hrs_worked;

                                           //processing section




if (hrs_worked == 40)
     { reg_pay = hrs_worked * reg_rate;
     ot_pay = 0;}
else if (hrs_worked >= 40)
     {reg_pay = hrs_worked * reg_rate;
      ot_pay = (hrs_worked - 40) * 1.5 * reg_rate;}
else if (hrs_worked <= 40)
     {reg_pay = hrs_worked * reg_rate;;
      ot_pay = 0;}

ot_hours = hrs_worked - 40;
if (hrs_worked <= 40)
   {ot_hours = 0;}

total_pay = ot_pay + reg_pay;

                                       //outputing section


system("cls");
cout << setw(48) << "The corporation" << endl;
cout << setw(48) << "====================" << endl;
cout << setw(10) << "Employee Name: " << setw(5) << name << setw(20) << "ID. Number: " << setw(5)
<< employeeid << endl;
cout << setw(10) << "Job Classification: " << setw(5) << class_id << setw(20) << "Hourly Rate: " << setw(5) 
<< reg_rate << endl;
cout << setw(10) << "Total Hours Worked: " << setw(5) << hrs_worked << setw(20) << "Overtime Hours: " << 
setw(5) << ot_hours << endl;
cout << setw(10) << "Regular Pay: " << setw(12) << reg_pay << setw(20) << "Overtime Pay: " << setw(5) <<
 ot_pay << endl;
cout << setw(48) << "Total Earnings ......... " << setw(5) << total_pay << endl;


system("pause");
}




EDIT: I was basing my opinion on do loop off this youtube video
http://www.youtube.com/watch?v=BVVXLvMs_-w
It seemed closest to what I'm trying to accomplish but I'm not getting the same results.
Last edited on
I was able to figure it out up to

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
int main()
{
                                     
int                              class_id;                     
double                           employeeid,
                                 hrs_worked,
                                 ot_hours,
                                 total_pay,
                                 ot_pay,
                                 reg_rate,
                                 reg_pay;                  
char                             name[30],
                                 cContinue;        
                                                  
                                                  //input section                                         
                                           
do {
cout << "The Employee's Name: ";
cin >> ws;
cin.getline(name,(sizeof(name)-1));

cout << "The Employee's Id. Number: ";
cin >> employeeid; 

cout << "The Employee's Job Classification Number: ";
cin >> class_id;

switch (class_id)
{
case 1:    reg_rate = 5.00;
             break;
case 2:    reg_rate = 6.00;
             break;
case 3:    reg_rate = 9.00;
             break;
case 4:    reg_rate = 12.00;
             break;
default:   reg_rate = 5.00;
           break;           
}

cout << "The Number of Hours Worked. ";
cin >> hrs_worked;

                                           //process section




if (hrs_worked == 40)
     { reg_pay = hrs_worked * reg_rate;
     ot_pay = 0;}
else if (hrs_worked >= 40)
     {reg_pay = hrs_worked * reg_rate;
      ot_pay = (hrs_worked - 40) * 1.5 * reg_rate;}
else if (hrs_worked <= 40)
     {reg_pay = hrs_worked * reg_rate;;
      ot_pay = 0;}

ot_hours = hrs_worked - 40;
if (hrs_worked <= 40)
   {ot_hours = 0;}

total_pay = ot_pay + reg_pay;

                                       //output section


system("cls");
cout << setw(48) << "WorkHard Corporation" << endl;
cout << setw(48) << "====================" << endl;
cout << setw(10) << "Employee Name: " << setw(5) << name << setw(20) << "ID. Number: " << setw(5)
<< employeeid << endl;
cout << setw(10) << "Job Classification: " << setw(5) << class_id << setw(20) << "Hourly Rate: " << setw(5) 
<< reg_rate << endl;
cout << setw(10) << "Total Hours Worked: " << setw(5) << hrs_worked << setw(20) << "Overtime Hours: " << 
setw(5) << ot_hours << endl;
cout << setw(10) << "Regular Pay: " << setw(12) << reg_pay << setw(20) << "Overtime Pay: " << setw(5) <<
 ot_pay << endl;
cout << setw(48) << "Total Earnings ......... " << setw(5) << total_pay << endl;
cout << "***********************************************************" << endl;

cout << "Continue(y/n)?" << std::endl;
cin >> cContinue;
  } while (cContinue == 'y' || 'Y');
  
system("pause");
}




Can I make multiple outputs appear at once or does the previous output need to be cleared? Also how do I send multiple outputs to a file?
Can anyone help?
Topic archived. No new replies allowed.