I think when you have a variable like "choice" that can have more than two values, you should use a switch statement (assuming that your variable is an integer expression.) The code ends up being cleaner, easier to read, and easier to maintain.
#include <iostream>
usingnamespace std;
int staff_menu(int choice, int item_w, int bil_item, int choice1, double total);
float admin_menu();
void main()
{
staff_menu(int choice, int item_w, int bil_item, int choice1, double total);
}
staff_menu(int choice, int item_w, int bil_item, int choice1, double total)
{
cout << "\t\t\t\t STAFF MENU" << endl;
cout << "\t\t\t********************************" << endl;
cout << "\t\t\t1. View Staff Schedule" << endl;
cout << "\t\t\t2. Calculate Total Item Recycled" << endl;
cout << "\t\t\t3. Print Report" << endl;
cout << "\t\t\t4. Back" << endl;
cout << "\t\t\t********************************\n" << endl;
cout << "->>Please enter your choice" << endl;
cin >> choice;
if (choice == 1)
{
//jadual staf
cout << "\nStaff Schedule" << endl;
}
elseif (choice == 2)
{
//kira
cout << "\nCalculate Total Item Recycled" << endl;
cout << "\nEnter item weight" << endl;
cout << "\nItem weight = "; cin >> item_w;
cout << "\nEnter number of item recycled" << endl;
cout << "\nNumber of item recycled = "; cin >> bil_item;
total=item_w*bil_item;
cout << "\nTotal Item Recycled is " << total << " metric tons" << endl;
}
elseif (choice == 3)
{
//report
cout << "\nPrint Report" << endl;
cout << "Select which report to be print" << endl;
cout << "1. Staff's monthly payroll " << endl;
cout << "2. Total item recycled " << endl;
}
cin >> choice1;
if (choice1 == 1)
{
cout << "\nStaff's monthly payroll" << endl;
}
elseif (choice1 == 2)
{
cout << " Total item recycled " << endl;
}
return 0;
}
error:
1>c:\users\nasr\documents\visual studio 2010\projects\xv2\xv2\lll.cpp(9): error C2144: syntax error : 'int' should be preceded by ')'
1>c:\users\nasr\documents\visual studio 2010\projects\xv2\xv2\lll.cpp(9): error C2660: 'staff_menu' : function does not take 0 arguments
1>c:\users\nasr\documents\visual studio 2010\projects\xv2\xv2\lll.cpp(9): error C2059: syntax error : ')'
1>c:\users\nasr\documents\visual studio 2010\projects\xv2\xv2\lll.cpp(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
A prototype tells the compiler what to expect when you define a function. You prototype it with a return value of an integer (int) then when you define it you don't give it any return type. Then you are trying to return 0 (int). Also line 9 you are calling it wrong. What you are doing is essentially this: