Program needs a menu.

Need a menu for function line 78 that will displays 1-6 options. Please help.

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

void getEmployeeInfor(double &IDnumber, double &rate, double &hours);
double calcWage(double rate, double hours);
void printWages(ofstream &outputFile, double IDnumber, double rate, double hours, double wage);
void printEmployees(double employees[30][4], int amount);

int main() // The main function that runs everything.
{
  double employees[30][4];
  
	double ID;
	double r;
	double hrs;
	double wages; 
	ofstream outputFile;
    outputFile.open("employeeWages.dat"); // Open the file. The file name is employeeWages.dat
  	char choice; // This is the variable for Y = yes, N = no
  	int i=0; //Variable load the employees
  
  	do {
	getEmployeeInfor(ID, r, hrs); 
	wages = calcWage(r, hrs); // Calculating the gross wage using Rate times Hours
    employees[i][0]=ID; //Storing the ID into the array
    employees[i][1]=r; //Storing the rate
    employees[i][2]=hrs;
    employees[i][3]=wages;
	printWages(outputFile, ID, r, hrs, wages);
    i++; //Incrementing the amount of employees
	
	
		cout << "Do you want to calculate another employee's gross wage? "; // After the user's has enter their values, this text will display to ask the user if the user want to calculate another employee's gross wage.
        cin >> choice;
	   } while (choice == 'y' || choice == 'Y'); // If use decides to report another employee's gross wage, press "y" to run the program again. This message will display. 
	 cout << "The result is report to the file employeeWages.dat" << endl; // This message will display once the user's is done with their reports, simply press n, which means no. As long as the user doesn't press "y" or "Y" the program will not re run.
	return 0;   
}

void getEmployeeInfor(double &IDnumber, double &rate, double &hours) // This function is for getting the information from the emoployee's ID, their pay rate, and their working hours.
{
	cout << "                 -- XXXXXX Payroll System --" << endl;
	cout << "                   Build Employee Database" << endl << endl;
	cout << "Enter an employee's information by the order of ID number, rate, and hours:" << endl; // This text will display when running the program by typing ./a.out
    cin >> IDnumber >> rate >> hours; // Input values for employee's ID, pay rate, and working hours.
     while ( rate < 0 || hours < 0 || IDnumber < 0) // This indicates that the values inputs of employee's ID, pay rate, and working hours cannot be a negative number.
     {
	  cout << "You must enter a non negative value. Try again!" << endl; // This text will display if the input values for emoployee's ID, pay rate, and working hours are negative numbers.
	  cin >> IDnumber >> rate >> hours;
     }
}

double calcWage(double rate, double hours) // This function calculates the employee's gross wage.
{  
	return rate * hours; // Returning rate times hours to create the gross's wage which is named "wage".
}

void printEmployees(double employees[30][4], int amount)
{
  cout<<"ID"<<"Hours rate"<<"Hours worked"<<"Wage"<<endl;
  	for(int i=0; i < amount; i++){
      cout<<employees[i][0]<<employees[i][1]<<employees[i][2]<<employees[i][3]<<endl;
    }  
  
}

void printWages(ofstream &outputFile, double IDnumber, double rate, double hours, double wage) // This function is based on the files for employeeWages.dat, entering those data into file: employeeWages.dat
{   
	outputFile.precision(2);
    outputFile << std::fixed;
    outputFile << "        ID" << "         Hourly Rate" << "     Hours" << "                Wage" << endl;
	outputFile << "------------------------------------------------------------" << endl;
	outputFile << "        " << IDnumber << "               " << rate << "     " << hours << "             " << wage << endl;
}

void menuOptions(double employees[30][4], int amount, double &IDnumber, double &rate, double &hours)
{
int option;
  
  do {
  	  cout << "                 -- XXXXXX Payroll System --" << endl;
  	  cout << "                   Display Employee Data" << endl << endl;
  
	  cout << "1. Display employees' information to screen" << endl;
  	  cout << "2. Display employees' information to screen according the order of ID" << endl;
  	  cout << "3. Display employees’ information to screen according the order of hourly rate" << endl;
      cout << "4. Display employees’ information to screen according the order of hours worked" << endl; 
      cout << "5. Display employees’ information to screen according the order of wage" << endl;
  	  cout << "6. Quit the system" << endl << endl;
      cout << "Enter your option --> ";
      cin >> option;
	  
  }
}
Last edited on
(Apart from syntax errors,) that function already outputs a "menu". What is the actual problem?
thats the menu function but it is not finish, wondering what i can do to make a menu. like using if else. But i am not sure how it works.
"What to do on certain input" is separate from "show menu".

There are multiple approaches for handling input:
if .. else if ..
switch
lookup table


About "how", see http://www.cplusplus.com/doc/tutorial/control/
Topic archived. No new replies allowed.