Click here to Skip to main content
Sign Up to vote bad
good
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 3 Oct '12 - 22:49
jonnard337
Edited 3 Oct '12 - 22:51


3 solutions

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!
  Permalink  
If a function is declared to return a value, you must return a value:
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.
  Permalink  
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.
  Permalink  
Comments
Espen Harlinn - 4 Oct '12 - 4:55
5'ed!
jonnard - 4 Oct '12 - 5:25
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:30
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:43
#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:37
sir where should I put the function get_info/. because in my code i put it there.. can i post my code again???
JF2015 - 4 Oct '12 - 6:15
Don't you see that the function get_info() does appear in your code two time?? This is not allowed. You may rename the second function to e.g. get_detailed_info().
Stefan_Lang - 4 Oct '12 - 11:48
You made a mistake in your correction: instead of just changing the return type on one function, you additionally changed the entire name of the last function from display_info to get_info! Change it back and you should be good.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 495
1 OriginalGriff 273
2 Dave Kreskowiak 175
3 Mohammed Hameed 145
4 Mayur_Panchal 144
0 Sergey Alexandrovich Kryukov 8,123
1 OriginalGriff 6,173
2 CPallini 3,482
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid