Need help with my Payroll System problems

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

45 Replies - 19771 Views - Last Post: 08 October 2013 - 03:46 AM Rate Topic: ***-- 2 Votes

#1 SHENGTON   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

Need help with my Payroll System problems

Posted 19 October 2010 - 10:35 PM

Hello again, good afternoon. :)

I'm a student and this Payroll System is a project.

Ok, I didn't include the "Create Payroll" and "Delete Employee" codes yet. For now, I'll try to focus the problem with my "Registering and Updating/Editing Employees" first with your help gurus.

Problems:
1. I'm not sure if my codes for "Registering" will move to the next array in order to add another employee again.
2. My "Updating/Editing Employees" isn't working. When I try to input a wrong employee number it won't prompt any error instead it will proceed to this line "Are you sure you want to edit? (Y or N):".

Hope you can help me. Thanks! :)

Here's the code of my Payroll System:
#include <stdio.h>

#include <conio.h>

#include <string.h>



void main()

{

 char fname[100],lname[100],sex[100],address[100],dob[100];

 int empno[100],rate[100];

 int cho,choi;

 int i=0,found=0;

 int emp;

 char ans;

 clrscr();

 do

 {

  clrscr();

  printf("\n\t\t******************************************");

  printf("\n\t\t******* P A Y R O L L   S Y S T E M ******");

  printf("\n\t\t******************************************");

  printf("\n\n\t\t [1] Register New Employees\n");

  printf("\t\t [2] Manage Employees\n");

  printf("\t\t [3] Create Payroll\n");

  printf("\t\t [4] Exit\n");

  printf("\n\t\t Enter your choice: ");

  scanf("%d", &cho);

  switch(cho)

  {

   case 1:

   {

    found = 1;

    clrscr();

    printf("\n\t\t******************************************");

    printf("\n\t\t********* REGISTER NEW EMPLOYEE **********");

    printf("\n\t\t******************************************");

    printf("\n\n\t\t Employee No.: ");

    scanf(" %d",&empno[i]);

    printf("\t\t First Name: ");

    scanf(" %s",fname[i]);

    printf("\t\t Last Name: ");

    scanf(" %s",lname[i]);

    printf("\t\t Date of Birth: ");

    scanf(" %s",dob[i]);

    printf("\t\t Sex: ");

    scanf(" %s",sex[i]);

    printf("\t\t Address: ");

    scanf(" %s",address[i]);

    printf("\t\t Rate/Hour: ");

    scanf(" %d",&rate[i]);

    printf("\n\t\t INFOMATION HAS BEEN SAVED. THANK YOU!!!");

    i++;

    getch();

    break;

   }

   case 2:

   {

    clrscr();

    printf("\n\t\t******************************************");

    printf("\n\t\t************ MANAGE EMPLOYEES ************");

    printf("\n\t\t******************************************");

    printf("\n\n\t\t [1] Update/Edit Employee\n");

    printf("\t\t [2] Delete Employee\n");

    printf("\t\t [3] Back to Main Menu\n");

    printf("\n\t\t Enter your choice: ");

    scanf("%d",&choi);

    switch(choi)

    {

     case 1:

     {

      clrscr();

      printf("\n\t\t******************************************");

      printf("\n\t\t********** UPDATE/EDIT EMPLOYEE **********");

      printf("\n\t\t******************************************");

      printf("\n\n\t\t Enter Employee Number: ");

      scanf(" %d",&emp);

      if(emp == empno[i])

      {

       found = 1;

      }

      else

      {

       printf(" Employee not found.");

      }

      if(found == 1)

      {

       printf("\n\t\t Are you sure you want to edit? (Y or N): ");

       scanf(" %c",&ans);

       if(ans == 'Y')

       {

        printf("\n\t\t [1] Employee Number");

        printf("\n\t\t [2] First Name");

        printf("\n\t\t [3] Last Name");

        printf("\n\t\t [4] Date of Birth");

        printf("\n\t\t [5] Sex");

        printf("\n\t\t [6] Address");

        printf("\n\t\t [7] Rate/Hour");

        printf("\n\n\t\t What do you want to edit?: ");

        scanf(" %s",&empno);

       }

      }

      break;

     }

     case 2:

     {

      clrscr();

      printf("\n\t\t******************************************");

      printf("\n\t\t************ DELETE EMPLOYEE *************");

      printf("\n\t\t******************************************");

      printf("\n\n\t\t Enter Employee Number: ");

      scanf(" %d",&emp);

      printf("\n\t\t Are you sure you want to delete Employee?\n\t\t Press Y (yes) or N (no):");

      scanf(" %c",&ans);

      printf("\n\t\t EMPLOYEE HAS BEEN DELETED.");

      getch();

      break;

     }

    }

   }

  }

 }while(cho!=4);

}


Is This A Good Question/Topic? 0
  • +

Replies To: Need help with my Payroll System problems

#2 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Need help with my Payroll System problems

Posted 19 October 2010 - 10:59 PM

Here's what the compiler thinks about your code
dic.c:6: warning: return type of ‘main’ is not ‘int’
dic.c: In function ‘main’:
dic.c:40: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
dic.c:42: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
dic.c:44: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
dic.c:46: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
dic.c:48: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
dic.c:102: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int (*)[100]’



"void main()" is wrong. Always use "int main()".
Read here the words of the man who invented C++:
http://www.research.....html#void-main
Can I write "void main()"?
The definition
void main() { /* ... */ }
is not and never has been C++, nor has it ever been C. See the ISO C++ standard 3.6.1[2] or the ISO C standard 5.1.2.2.1.


The line numbers in the above refer to this version of your code. Having every second line blank just makes your code ugly and hard to read.
#include <stdio.h>
// #include <conio.h>
#include <string.h>

void main()
{
    char fname[100],lname[100],sex[100],address[100],dob[100];
    int empno[100],rate[100];
    int cho,choi;
    int i=0,found=0;
    int emp;
    char ans;
    // clrscr();
    
    do
    {
        // clrscr();
        printf("\n\t\t******************************************");
        printf("\n\t\t******* P A Y R O L L   S Y S T E M ******");
        printf("\n\t\t******************************************");
        printf("\n\n\t\t [1] Register New Employees\n");
        printf("\t\t [2] Manage Employees\n");
        printf("\t\t [3] Create Payroll\n");
        printf("\t\t [4] Exit\n");
        printf("\n\t\t Enter your choice: ");
        scanf("%d", &cho);
        
        switch(cho)
        {
            case 1:
            {
                found = 1;
                // clrscr();
                printf("\n\t\t******************************************");
                printf("\n\t\t********* REGISTER NEW EMPLOYEE **********");
                printf("\n\t\t******************************************");
                printf("\n\n\t\t Employee No.: ");
                scanf("%d",&empno[i]);
                printf("\t\t First Name: ");
                scanf("%s",fname[i]);
                printf("\t\t Last Name: ");
                scanf("%s",lname[i]);
                printf("\t\t Date of Birth: ");
                scanf("%s",dob[i]);
                printf("\t\t Sex: ");
                scanf("%s",sex[i]);
                printf("\t\t Address: ");
                scanf("%s",address[i]);
                printf("\t\t Rate/Hour: ");
                scanf("%d",&rate[i]);
                printf("\n\t\t INFOMATION HAS BEEN SAVED. THANK YOU!!!");
                i++;
                // getch();
                break;
            }
            case 2:
            {
                // clrscr();
                printf("\n\t\t******************************************");
                printf("\n\t\t************ MANAGE EMPLOYEES ************");
                printf("\n\t\t******************************************");
                printf("\n\n\t\t [1] Update/Edit Employee\n");
                printf("\t\t [2] Delete Employee\n");
                printf("\t\t [3] Back to Main Menu\n");
                printf("\n\t\t Enter your choice: ");
                scanf("%d",&choi);
                
                switch(choi)
                {
                    case 1:
                    {
                        // clrscr();
                        printf("\n\t\t******************************************");
                        printf("\n\t\t********** UPDATE/EDIT EMPLOYEE **********");
                        printf("\n\t\t******************************************");
                        printf("\n\n\t\t Enter Employee Number: ");
                        scanf("%d",&emp);
                        
                        if(emp == empno[i])
                        {
                            found = 1;
                        }
                        else
                        {
                            printf("Employee not found.");
                        }
      
                        if(found == 1)
                        {
                            printf("\n\t\t Are you sure you want to edit? (Y or N): ");
                            scanf("%c",&ans);
                            if(ans == 'Y')
                            {
                                printf("\n\t\t [1] Employee Number");
                                printf("\n\t\t [2] First Name");
                                printf("\n\t\t [3] Last Name");
                                printf("\n\t\t [4] Date of Birth");
                                printf("\n\t\t [5] Sex");
                                printf("\n\t\t [6] Address");
                                printf("\n\t\t [7] Rate/Hour");
                                printf("\n\n\t\t What do you want to edit?: ");
                                scanf("%s",&empno);
                            }
                        }
                        break;
                    }
                    case 2:
                    {
                        // clrscr();
                        printf("\n\t\t******************************************");
                        printf("\n\t\t************ DELETE EMPLOYEE *************");
                        printf("\n\t\t******************************************");
                        printf("\n\n\t\t Enter Employee Number: ");
                        scanf("%d",&emp);
                        printf("\n\t\t Are you sure you want to delete Employee?\n\t\t Press Y (yes) or N (no):");
                        scanf("%c",&ans);
                        printf("\n\t\t EMPLOYEE HAS BEEN DELETED.");
                        // getch();
                        break;
                    }
                }
            }
        }
    }while(cho!=4);
}


This post has been edited by janotte: 19 October 2010 - 11:00 PM

Was This Post Helpful? 0
  • +
  • -

#3 SHENGTON   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

Re: Need help with my Payroll System problems

Posted 19 October 2010 - 11:51 PM

Hello :)

Thanks for helping me again janotte.

I changed the "fname[i]" to "fname" and so on, since which I think is right(correct me if I'm wrong). However, in the Updating/Editing part still don't work. If I try to input a wrong employee number still it will print this line "Are you sure you want to edit? (Y or N):". If I try to input the correct employee number, the program will print this "EMPLOYEE NOT FOUND."

What I want to happen is:
When a user input an incorrect employee number, it will go back to the "Manage Employees" menu. And when the user inputs the correct employee number, that's the time this line will appear "Are you sure you want to edit? (Y or N):".

In the editing question part, I'll post my codes later.

Here's the edited codes of Register and Update/Edit Employees:
int main()
{
 char fname[100],lname[100],sex[100],address[100],dob[100];
 int empno[100],rate[100];
 int cho,choi;
 int i=0,found=0;
 int emp,edit;
 char ans;
 clrscr();
 do
 {
  clrscr();
  printf("\n\t\t******************************************");
  printf("\n\t\t******* P A Y R O L L   S Y S T E M ******");
  printf("\n\t\t******************************************");
  printf("\n\n\t\t [1] Register New Employees\n");
  printf("\t\t [2] Manage Employees\n");
  printf("\t\t [3] Create Payroll\n");
  printf("\t\t [4] Exit\n");
  printf("\n\t\t Enter your choice: ");
  scanf("%d", &cho);
  switch(cho)
  {
   case 1:
   {
    found = 1;
    clrscr();
    printf("\n\t\t******************************************");
    printf("\n\t\t********* REGISTER NEW EMPLOYEE **********");
    printf("\n\t\t******************************************");
    printf("\n\n\t\t Employee No.: ");
    scanf(" %d",&empno[i]);
    printf("\t\t First Name: ");
    scanf(" %s",fname);
    printf("\t\t Last Name: ");
    scanf(" %s",lname);
    printf("\t\t Date of Birth: ");
    scanf(" %s",dob);
    printf("\t\t Sex: ");
    scanf(" %s",sex);
    printf("\t\t Address: ");
    scanf(" %s",address);
    printf("\t\t Rate/Hour: ");
    scanf(" %d",&rate[i]);
    printf("\n\t\t INFOMATION HAS BEEN SAVED. THANK YOU!!!");
    i++;
    getch();
    break;
   }
   case 2:
   {
    clrscr();
    printf("\n\t\t******************************************");
    printf("\n\t\t************ MANAGE EMPLOYEES ************");
    printf("\n\t\t******************************************");
    printf("\n\n\t\t [1] Update/Edit Employee\n");
    printf("\t\t [2] Delete Employee\n");
    printf("\t\t [3] Back to Main Menu\n");
    printf("\n\t\t Enter your choice: ");
    scanf("%d",&choi);
    switch(choi)
    {
     case 1:
     {
      clrscr();
      printf("\n\t\t******************************************");
      printf("\n\t\t********** UPDATE/EDIT EMPLOYEE **********");
      printf("\n\t\t******************************************");
      printf("\n\n\t\t Enter Employee Number: ");
      scanf(" %d",&emp);
      if(emp != empno[i])
      {
       printf("\n\t\t EMPLOYEE NOT FOUND.");
       i++;
      }
      else
      {
       printf("\n\t\t EMPLOYEE FOUND.");
       found = 1;
      }
      if(found == 1)
      {
       printf("\n\t\t Are you sure you want to edit? (Y or N): ");
       scanf(" %c",&ans);
       if(ans == 'Y' || ans == 'y')
       {
        printf("\n\t\t [1] Employee Number");
        printf("\n\t\t [2] First Name");
        printf("\n\t\t [3] Last Name");
        printf("\n\t\t [4] Date of Birth");
        printf("\n\t\t [5] Sex");
        printf("\n\t\t [6] Address");
        printf("\n\t\t [7] Rate/Hour");
        printf("\n\n\t\t What do you want to edit?: ");
        scanf(" %d",&edit);
       }
      }
      break;
     }

This post has been edited by SHENGTON: 20 October 2010 - 12:58 AM

Was This Post Helpful? 0
  • +
  • -

#4 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 01:38 AM

So you want your output to look like this?
		******************************************
		************ MANAGE EMPLOYEES ************
		******************************************

		 [1] Update/Edit Employee
		 [2] Delete Employee
		 [3] Back to Main Menu

		 Enter your choice: 1

		******************************************
		********** UPDATE/EDIT EMPLOYEE **********
		******************************************

		 Enter Employee Number: 8

		 EMPLOYEE NOT FOUND.
		******************************************
		******* P A Y R O L L   S Y S T E M ******
		******************************************

		 [1] Register New Employees
		 [2] Manage Employees
		 [3] Create Payroll
		 [4] Exit

		 Enter your choice: 


Is that right?
Was This Post Helpful? 0
  • +
  • -

#5 SHENGTON   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 04:25 AM

Hello janotte, good evening. :)

Thanks for replying.

Here's what I want to happen with my "Register New Employees" and "Update/Edit Employees"

User register an employee:
******************************************
******* P A Y R O L L   S Y S T E M ******
******************************************

 [1] Register New Employees
 [2] Manage Employees
 [3] Create Payroll
 [4] Exit

 Enter your choice:1

******************************************");
********* REGISTER NEW EMPLOYEES *********");
******************************************");

 Employee No.:8
 First Name:Vhong
 Last Name:Navarro
 Date of Birth:10-12-1986
 Sex:Male
 Address:Philippines
 Rate/Hour:350

 INFOMATION HAS BEEN SAVED. THANK YOU!!!

******************************************
******* P A Y R O L L   S Y S T E M ******
******************************************

 [1] Register New Employees
 [2] Manage Employees
 [3] Create Payroll
 [4] Exit

 Enter your choice:




When a user inputs a wrong employee number:
******************************************
******* P A Y R O L L   S Y S T E M ******
******************************************

 [1] Register New Employees
 [2] Manage Employees
 [3] Create Payroll
 [4] Exit

 Enter your choice: 2

******************************************
************ MANAGE EMPLOYEES ************
******************************************

 [1] Update/Edit Employee
 [2] Delete Employee
 [3] Back to Main Menu

 Enter your choice: 1

******************************************
********** UPDATE/EDIT EMPLOYEE **********
******************************************

 Enter Employee Number: 8

 EMPLOYEE NOT FOUND.

******************************************
************ MANAGE EMPLOYEES ************
******************************************

 [1] Update/Edit Employee
 [2] Delete Employee
 [3] Back to Main Menu

 Enter your choice:


When a user inputs an incorrect employee number, it will go back to the "Manage Employees" menu.



When a user inputs the correct employee number:
******************************************
******* P A Y R O L L   S Y S T E M ******
******************************************

 [1] Register New Employees
 [2] Manage Employees
 [3] Create Payroll
 [4] Exit

 Enter your choice:2

******************************************
************ MANAGE EMPLOYEES ************
******************************************

 [1] Update/Edit Employee
 [2] Delete Employee
 [3] Back to Main Menu

 Enter your choice: 1

******************************************
********** UPDATE/EDIT EMPLOYEE **********
******************************************

 Enter Employee Number: 8

 EMPLOYEE FOUND.

 Are you sure you want to edit? (Y or N):
 [1] Employee Number
 [2] First Name
 [3] Last Name
 [4] Date of Birth
 [5] Sex
 [6] Address
 [7] Rate/Hour

 What do you want to edit?:2

 First Name:Vhong
 
 INFORMATION HAS BEEN UPDATED.

******************************************
******* P A Y R O L L   S Y S T E M ******
******************************************

 [1] Register New Employees
 [2] Manage Employees
 [3] Create Payroll
 [4] Exit

 Enter your choice: 

This post has been edited by SHENGTON: 20 October 2010 - 04:26 AM

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6257
  • View blog
  • Posts: 24,025
  • Joined: 23-August 08

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 04:29 AM

So...what's the problem then?
Was This Post Helpful? 0
  • +
  • -

#7 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 04:47 AM

Okay I see now.
Well the reason the the program loops back to this menu
******************************************
******* P A Y R O L L   S Y S T E M ******
******************************************
 
 [1] Register New Employees

 [2] Manage Employees
 [3] Create Payroll
 [4] Exit

 Enter your choice:


is because that menu is at the top of the only loop in your program.

If you want the code to loop back to sub-menu you are going to have to wrap the sub-menu/s in loops too.
Very much using the same logic and syntax that you have for the existing loop.
Make sense?
Was This Post Helpful? 1
  • +
  • -

#8 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 05:24 AM

While you are starting to improve your code it is seriously time to start decomposing your program into functions.
Also time to start using some meaningful variable names to get away from things like "cho" and "choi".
Do you understand what a function is and how to write them?

Look at what I have done here with your initial menu.
Does it make sense? Can you see how pulling these great lumps of code out and putting them neatly aside in their own functions will make your code far more organised and easy to work on?
You really are at the point where you need to start making use of functions or your code will become completely unwieldy very quickly.
Can you decompose other functions out of your existing code? Give it a try.

BTW - I think you have already worked this out but I need to comment out the conio.h specific stuff for your code to compile on my machine.
You will need to uncomment that stuff if your want it in your code.

#include <stdio.h>
// #include <conio.h>
#include <string.h>

int payrollSystemMenu();

int main()
{
 char fname[100],lname[100],sex[100],address[100],dob[100];
 int empno[100],rate[100];
 int payrollSystemMenuChoice,choi;
 int i=0,found=0;
 int emp,edit;
 char ans;
 //clrscr();
 do
 {
  payrollSystemMenuChoice = payrollSystemMenu();

  switch(payrollSystemMenuChoice)
  {
   case 1:
   {
    found = 1;
    //clrscr();
    printf("\n\t\t******************************************");
    printf("\n\t\t********* REGISTER NEW EMPLOYEE **********");
    printf("\n\t\t******************************************");
    printf("\n\n\t\t Employee No.: ");
    scanf(" %d",&empno[i]);
    printf("\t\t First Name: ");
    scanf(" %s",fname);
    printf("\t\t Last Name: ");
    scanf(" %s",lname);
    printf("\t\t Date of Birth: ");
    scanf(" %s",dob);
    printf("\t\t Sex: ");
    scanf(" %s",sex);
    printf("\t\t Address: ");
    scanf(" %s",address);
    printf("\t\t Rate/Hour: ");
    scanf(" %d",&rate[i]);
    printf("\n\t\t INFOMATION HAS BEEN SAVED. THANK YOU!!!");
    i++;
    //getch();
    break;
   }
   case 2:
   {
    //clrscr();
    printf("\n\t\t******************************************");
    printf("\n\t\t************ MANAGE EMPLOYEES ************");
    printf("\n\t\t******************************************");
    printf("\n\n\t\t [1] Update/Edit Employee\n");
    printf("\t\t [2] Delete Employee\n");
    printf("\t\t [3] Back to Main Menu\n");
    printf("\n\t\t Enter your choice: ");
    scanf("%d",&choi);
    switch(choi)
    {
     case 1:
     {
      //clrscr();
      printf("\n\t\t******************************************");
      printf("\n\t\t********** UPDATE/EDIT EMPLOYEE **********");
      printf("\n\t\t******************************************");
      printf("\n\n\t\t Enter Employee Number: ");
      scanf(" %d",&emp);
      if(emp != empno[i])
      {
       printf("\n\t\t EMPLOYEE NOT FOUND.");
       i++;
      }
      else
      {
       printf("\n\t\t EMPLOYEE FOUND.");
       found = 1;
      }
      if(found == 1)
      {
       printf("\n\t\t Are you sure you want to edit? (Y or N): ");
       scanf(" %c",&ans);
       if(ans == 'Y' || ans == 'y')
       {
        printf("\n\t\t [1] Employee Number");
        printf("\n\t\t [2] First Name");
        printf("\n\t\t [3] Last Name");
        printf("\n\t\t [4] Date of Birth");
        printf("\n\t\t [5] Sex");
        printf("\n\t\t [6] Address");
        printf("\n\t\t [7] Rate/Hour");
        printf("\n\n\t\t What do you want to edit?: ");
        scanf(" %d",&edit);
       }
      }
      break;
     }
    }
   }
  }
 }while(payrollSystemMenuChoice != 4);
 return 0;
}


int payrollSystemMenu(){
	int userChoice;
	//clrscr();
	printf("\n\t\t******************************************");
	printf("\n\t\t******* P A Y R O L L   S Y S T E M ******");
	printf("\n\t\t******************************************");
	printf("\n\n\t\t [1] Register New Employees\n");
	printf("\t\t [2] Manage Employees\n");
	printf("\t\t [3] Create Payroll\n");
	printf("\t\t [4] Exit\n");
	printf("\n\t\t Enter your choice: ");
	scanf("%d", &userChoice);
	
	return userChoice;
}


Was This Post Helpful? 1
  • +
  • -

#9 SHENGTON   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 05:56 AM

Ahh ok, thanks for the explanations janotte.

I understand about the functions a little bit. I'll give it a try janotte. I'll try to post the functions next time.

Anyway, lets try to go back with my first problem about "Register New Employees". I'm not sure if my codes for "Registering" will move to the next array in order to add another employee again. See below if what I want to happen.

Empty Array:
 ________________________________________
|       |       |       |       |       |
|       |       |       |       |       |
|_______|_______|_______|_______|_______|



Register a new employee:
 ________________________________________
|       |       |       |       |       |
| Vhong |       |       |       |       |
|_______|_______|_______|_______|_______|



Register new employee again:
 _________________________________________
|       |        |       |       |       |
| Vhong | Justin |       |       |       |
|_______|________|_______|_______|_______|



Register new employee again and so on:
 __________________________________________
|       |        |        |       |       |
| Vhong | Justin | Kristy |       |       |
|_______|________|________|_______|_______|


Does my codes work the same above?

This post has been edited by SHENGTON: 20 October 2010 - 05:59 AM

Was This Post Helpful? 0
  • +
  • -

#10 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 06:18 AM

Let's look at these two data collection steps as an example
    printf("\n\n\t\t Employee No.: ");
    scanf(" %d",&empno[i]);
    printf("\t\t First Name: ");
    scanf(" %s",fname);



Your employee number is getting stored in an array and although I haven't tested it there is a good chance it will work as you hope.
However, the first name is not going into an array. So there is no chance it will work as you want.

You have an array declared here
char fname[100],...


but it is a character array (a single string or 100 individual characters - depends how you use it).
I think what you wanted to create there was an array of C-strings. So if a C-string is an array (and it is) then you need an array of arrays. You need to apply that thinking in the rest of the cases where you are collecting strings from the user.

The 'real' answer to a challenge like the one you are facing is a struct. Have you covered structs yet? If not just let it slide past and ignore that idea. If you have done structs in class/done that chapter in the textbook then here is a classic place to use a struct. That would require redesigning a fair whack of your code but would you pay you back in the long run.
Was This Post Helpful? 1
  • +
  • -

#11 newclearner   User is offline

  • D.I.C Regular

Reputation: 103
  • View blog
  • Posts: 302
  • Joined: 29-September 10

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 06:21 AM

View PostSHENGTON, on 20 October 2010 - 05:26 PM, said:

Does my codes work the same above?


In case of Employee No, and Rate yes it would move on to next position because they are arrays indexed by i.

But in case of rest of the details, it will replace the content of previous employee.

Reason - All your variables for holding FirstName, LastName, DOB, Sex, Address are single char arrays(basically a single string). And for holding multiple records you will need more than one strings i.e. array of strings means array of array of chars.

I hope that makes sense.
Was This Post Helpful? 1
  • +
  • -

#12 SHENGTON   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 06:25 AM

Hi janotte, good evening again.

You mean, you want me to use the Linked List?
Was This Post Helpful? 0
  • +
  • -

#13 newclearner   User is offline

  • D.I.C Regular

Reputation: 103
  • View blog
  • Posts: 302
  • Joined: 29-September 10

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 06:31 AM

No, janotte is talking about structures.

See this link: http://www.cprogramm...al/lesson7.html
Was This Post Helpful? 1
  • +
  • -

#14 janotte   User is offline

  • code > sword
  • member icon

Reputation: 991
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 06:38 AM

View PostSHENGTON, on 20 October 2010 - 10:25 PM, said:

You mean, you want me to use the Linked List?


I wasn't thinking of that. But it is a good answer if you want to try it. But that's a massive step up in complexity from where you are now. Do you think you can do it? Unless you really think you can I'd not bother.

Ahhh - is the struct thing confusing you?
A struct has nothing to do with linked lists.
This is some reading on structs
http://www.cplusplus...ial/structures/
Unless it looks familiar just forget about it and stick with the parallel arrays.
You seem badly out of your depth already, don't swim further from the shore without good reason.
Was This Post Helpful? 0
  • +
  • -

#15 SHENGTON   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 112
  • Joined: 10-October 08

Re: Need help with my Payroll System problems

Posted 20 October 2010 - 09:24 PM

Hello janotte and newclearner, good noon. :)

My instructor advice me to use the "2-Dimensional Array" since I'm using strings of array chars. Do you think it would work?

If YES, then do I have to declare another "int" variable again for the "scanf" of strings and increment it?

I mean like this: fname[i][j]

Thanks! :)

This post has been edited by SHENGTON: 20 October 2010 - 09:33 PM

Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »