Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <iostream>
#include <conio.h>
#include <string>
#include <iomanip>

using namespace std;

class payroll {

    private:

    string name;
    int days_work;
    float rate;
    float pay;
    float sss;
    float phil;
    float deduct;
    float totalpay;
    
    public :

      int get_info();
      void display_info();
};

////////////////////////////////////////////////////////////////////
const int PASSLEN = 4;

string passget();


void start()
	{

	string password;
	cout << "\n\n";
	cout << "\t SECURITY FORM";
	cout << "\n\n";
	cout << "Enter Your Password: ";
	password = passget();

	if (password == "bscs") {
	    cout << "\n\n";
	    cout << "Password Accepted";
	    cout << "\n\n\n";
        
        payroll emp;
        emp.get_info();
        emp.display_info();
	}
	else {
	    cout << "\n\n";
	    cout << "Password Denied Try Again !!!";
	    start();
	}
	}  // End of Start Function


int main()
{
    start();
	getch();
}

string passget()
{
	char password[PASSLEN], letter;
	int loop;
	int len;
	string password2;

		//Get Password and replace letters with *--------------
		loop = 0;
		while(loop != PASSLEN)
		{
			password[loop] = '\0';
			loop++;
		}
		loop = 0;
		len = 0;
		letter = '\0';
		while( letter != '\r' )
		{
			letter = getch();
			if( letter == '\b' && password[0] == '\0')
			{
				loop = 0;
				len = 0;
			}
			else
			{
				if( letter == '\b' && password[0] != '\0')
				{
					cout << "\b";
					cout << " ";
					cout << "\b";
					loop--;
					password[loop] = '\0';
					len--;
				}
				else
				{
					if( isprint( letter ) != 0 && loop < PASSLEN)
					{
						password[loop] = tolower(letter);
						cout << "*" ;
					}
					loop++;
					if (loop <= PASSLEN)
						len++;
				}
			}
		}

		//Convert Password from character array to string
		loop = 0;
		len = len;
		password2 = "";
		while (loop != len)
		{
		password2 = password2+password[loop];
		loop++;
		}

	return password2;
 } // End of Function Password

/////////////////////////////////////////////////////////////////////
int payroll :: get_info()
 {
     cout << "\t\t Welcome to Payroll System";
     cout << "\n\n";
     cout << "Enter Employees Name     : ";
     getline(cin,name);
     cout << "Enter No. of Days Worked : ";
     cin >> days_work;
     cout << "Enter Daily Rate         : ";
     cin >> rate;
     cout << "Enter SSS or GSIS        : ";
     cin >> sss;
     cout << "Enter Philhealth         : ";
     cin >> phil;
     
     cout << fixed << setprecision(4);
     pay = (days_work * rate);
     deduct = (sss + phil);
     totalpay= (pay - deduct);
 }

 void payroll ::display_info()
    {

     cout << "\n\n";
     cout << "*****@@---DETAILED REPORT---@@*****";
     cout << "\n\n";
     cout << "\nEmployees Name     : " << name;
     cout << "\n\n";
     cout << "\nEmployees Salay is : $" << pay;
     cout << "\n\n";
     cout << "\nEmployees SSS deduction is : $" << sss;
     cout << "\n\n";
     cout << "\nEmployees Philhealt deduction is : $" << phil;
     cout << "\n\n";
     cout << "\nEmployees Total deduction is : $" << deduct;
     cout << "\n\n";
     cout << "\n\n";
     cout << "\n\n";
     cout << "\nEmployees Total Salary is : $" << totalpay;
     cout << "\n\n";
     system("pause");
    }
////////////////////////////////////////////////

good day.. I need some help regarding this code for C++ because the errors are:

C:\Program Files\Microsoft Visual Studio\MyProjects\payroll daw\payroll nga daw.cpp(64) : warning C4508: 'main' : function should return a value; 'void' return type assumed

and


C:\Program Files\Microsoft Visual Studio\MyProjects\payroll daw\payroll nga daw.cpp(149) : error C4716: 'payroll::get_info' : must return a value


any one there who is willing to help..

Big Thanks..
Posted
Updated 3-Oct-12 22:51pm
v2

Just modify your code so that main() returns void as here:
void main()

And the function get_info() does also not need to return an integer, so change it to:
void payroll :: get_info()

Make sure to modify both the class definition as the code itself.
 
Share this answer
 
Comments
Espen Harlinn 4-Oct-12 4:55am    
5'ed!
jonnard 4-Oct-12 5:25am    
thank u sir.. still there's 1 error

here:

C:\Program Files\Microsoft Visual Studio\MyProjects\payroll daw\payroll nga daw.cpp(152) : error C2084: function 'void __thiscall payroll::get_info(void)' already has a body
Error executing cl.exe.
JF2015 4-Oct-12 5:30am    
This means that you did not modify the function get_info, but created a new one. Make sure you only have one function called get_info in your code.
jonnard 4-Oct-12 5:43am    
#include
#include
#include
#include

using namespace std;

class payroll {

private:

string name;
int days_work;
float rate;
float pay;
float sss;
float phil;
float deduct;
float totalpay;

public :

void get_info();
void display_info();
};

////////////////////////////////////////////////////////////////////
const int PASSLEN = 4;

string passget();


void start()
{

string password;
cout << "\n\n";
cout << "\t SECURITY FORM";
cout << "\n\n";
cout << "Enter Your Password: ";
password = passget();

if (password == "bscs") {
cout << "\n\n";
cout << "Password Accepted";
cout << "\n\n\n";

payroll emp;
emp.get_info();
emp.display_info();
}
else {
cout << "\n\n";
cout << "Password Denied Try Again !!!";
start();
}
} // End of Start Function


void main()
{
start();
getch();
}

string passget()
{
char password[PASSLEN], letter;
int loop;
int len;
string password2;

//Get Password and replace letters with *--------------
loop = 0;
while(loop != PASSLEN)
{
password[loop] = '\0';
loop++;
}
loop = 0;
len = 0;
letter = '\0';
while( letter != '\r' )
{
letter = getch();
if( letter == '\b' && password[0] == '\0')
{
loop = 0;
len = 0;
}
else
{
if( letter == '\b' && password[0] != '\0')
{
cout << "\b";
cout << " ";
cout << "\b";
loop--;
password[loop] = '\0';
len--;
}
else
{
if( isprint( letter ) != 0 && loop < PASSLEN)
{
password[loop] = tolower(letter);
cout << "*" ;
}
loop++;
if (loop <= PASSLEN)
len++;
}
}
}

//Convert Password from character array to string
loop = 0;
len = len;
password2 = "";
while (loop != len)
{
password2 = password2+password[loop];
loop++;
}

return password2;
} // End of Function Password

/////////////////////////////////////////////////////////////////////
void payroll :: get_info()
{
cout << "\t\t Welcome to Payroll System";
cout << "\n\n";
cout << "Enter Employees Name : ";
getline(cin,name);
cout << "Enter No. of Days Worked : ";
cin >> days_work;
cout << "Enter Daily Rate : ";
cin >> rate;
cout << "Enter SSS or GSIS : ";
cin >> sss;
cout << "Enter Philhealth : ";
cin >> phil;

cout << fixed << setprecision(4);
pay = (days_work * rate);
deduct = (sss + phil);
totalpay= (pay - deduct);
}

void payroll :: get_info()
{
cout << "\n\n";
cout << "*****@@---DETAILED REPORT---@@*****";
cout << "\n\n";
cout << "\nEmployees Name : " << name;
cout << "\n\n";
cout << "\nEmployees Salay is : $" << pay;
cout << "\n\n";
cout << "\nEmployees SSS deduction is : $" << sss;
cout << "\n\n";
cout << "\nEmployees Philhealt deduction is : $" << phil;
cout << "\n\n";
cout << "\nEmployees Total deduction is : $" << deduct;
cout << "\n\n";
cout << "\n\n";
cout << "\n\n";
cout << "\nEmployees Total Salary is : $" << totalpay;
cout << "\n\n";
system("pause");
}
///////////////////////////////////////////////
sir here's my code again i change my void
jonnard 4-Oct-12 5:37am    
sir where should I put the function get_info/. because in my code i put it there.. can i post my code again???
If a function is declared to return a value, you must return a value:
C++
int payroll::get_info()
{
    // must return a value here
    return 0;
}


You are only getting a warning for your main() function here because there is no declaration for main(). However, you should also return something there.
 
Share this answer
 
As a side note of what others have explained, return[^] values are used for two reasons mainly:

1. returning the value of a calculus or the result of the function called.
2. knowing if the functions has succeeded or not.

In your case both answers apply, you seem to be using global variables in your class so you don't have to return any value and both functions[^] are so easy that you don't need to check their success.

You should know that main return value[^] can be used to know the result of the application.

See the links to get more information.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900