Please help me with my code :)

Two questions.

1.) So I have four while loops, and I didn't close the code, reason being because I don't know where to put the brackets, so when I run the program, it loops infinitely. Please help me on where to put the brackets, when I try I get a lot of errors. Now someone did tell me I put way more while loops than need be, if that's the case what do i replace it with?

2.) How do I get an input and output for the code? I think I have to write a function but I have no idea which function to write, if you can help me with both that would be very much 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
#include <iostream> 
#include <string> 
#include <iomanip> 
#include <fstream> 
#include "Source.h"
using namespace std;

int main() 
{ 
    string payrate, hours, wages, name; 
    string inputfile, outputfile; 
    int empID; 
     


    cout << "Enter the name of the input file. "; 
        cin >> inputfile; 
        cout << "Enter the name of the output file. "; 
        cin >> outputfile; 

        cout << "Enter an employee number for your search. " << endl; 
        cin >> empID; 
		
		do
		{
			(empID > 0);
		} while cout << " The number you entered is valid " << endl;
        cin >> empID; 
		 (empID < 0);
           cout << " The number you entered is invalid, please enter a valid response. " << endl; 
     
        cout << "Employee " << empID << " worked " << hours << " hours " << " at " << payrate << " per hour and earned " << wages << endl; 
                 
        cout << "Enter an employee number for your search. " << endl; 
        cin >> empID; 
		do
		{
			(empID > 0);

		} while cout << " The number you entered is valid " << endl;
		(empID < 0);
            cout << " The number you entered is invalid, please enter a valid response. " << endl; 
            cin >> empID; 
        cout << "Employee " << empID << " worked " << hours << " hours " << " at " << payrate << " per hour and earned " << wages << endl; 
         
        cout << "Programmer, please enter your name here. " << endl; 
        cout << "Processing completed. " << endl; 
         
        system("pause"); 
            return 0; 

}

}
Last edited on
Line 23: If the user enters a valid (positive) employee id, you're going to loop forever on the cout statement.

Line 26: do is invalid by itself. If lines 24-24 are supposed to be conditional, they need to be surrounded by braces.

Line 10: hours,payrate,wages are all initialized to an empty strings.
Line 29: You're outputting an empty strings for hours, payrate and wages.

Lines 33-35: You need a refresher on do/while loops.
http://www.cplusplus.com/doc/tutorial/control/

Line 31-39: Why are you repeating your code here?

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
#include <iostream> 
#include <string> 
#include <fstream> 
using namespace std;

int main() 
{   string payrate, hours, wages, name; 
    string inputfile, outputfile; 
    int empID; 
     
    cout << "Enter the name of the input file. "; 
    cin >> inputfile; 
    cout << "Enter the name of the output file. "; 
    cin >> outputfile; 
    //  You need to open the input and output files
    
    cout << "Enter an employee number for your search. " << endl; 
    cin >> empID; 
    while (empID <= 0) 
    {   //  Not valid
        cout << " The number you entered is not valid " << endl; 
        cin >> empID; 
    }        
    //  Need to initialize hours, payrate and wages     
    cout << "Employee " << empID << " worked " << hours << " hours " << " at " << payrate << " per hour and earned " << wages << endl;                
    cout << "Processing completed. " << endl; 
    system("pause"); 
    return 0; 
}

Last edited on
Topic archived. No new replies allowed.