Like Tree2Likes
  • 1 Post By quzah
  • 1 Post By AndrewHunter

problem returning structure

This is a discussion on problem returning structure within the C Programming forums, part of the General Programming Boards category; i've tried the below program but it gives the error "two or more data types in declaration of `SalaryCal' " ...

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    2

    problem returning structure

    i've tried the below program but it gives the error "two or more data types in declaration of `SalaryCal' " i can't find the error, please help me

    Code:
    #include <stdio.h>
    #include <string.h>
    
    struct Employee
    {
        char EmployeeName[20];
        int EmployeeNo;
        float BasicSalary,AllowanceRate,Deduction;
    }
    
    struct Salary
    {
        int SalaryNo;
        float NetPayment;
    }
    
    struct Salary SalaryCal(struct Employee ED)
    {
        printf("\nName\tEmpNo\tBasicSalary\tAllowanceRate\tDeduction");
        printf("\n%s\t%4d\t%.2f\t%.2f\t%.2f",ED.EmployeeName,ED.EmployeeNo,ED.BasicSalary,ED.AllowanceRate,ED.Deduction);
    
        struct Salary SD;
        int i;
    
        SD.SalaryNo=ED.EmployeeNo;
    
        SD.NetPayment=ED.BasicSalary*ED.AllowanceRate-ED.Deduction;
    
        return(SD);
    }
    
    int main()
    {
        struct Employee Employee1;
    
        printf("\nEnter Employee's name: ");
        scanf("%s",&Employee1.EmployeeName);
        printf("\nEnter Employee Number: ");
        scanf("%s",&Employee1.EmployeeNo);
        printf("\nEnter Employee's Basic Salary: ");
        scanf("%s",&Employee1.BasicSalary);
        printf("\nEnter Employee's Allowance Rate: ");
        scanf("%s",&Employee1.AllowanceRate);
        printf("\nEnter Employee's Deduction: ");
        scanf("%s",&Employee1.Deduction);
    
        struct Salary Salary1;
    
        Salary1=SalaryCal(Employee1);
    
        printf("\n%s\t%f",Salary1.SalaryNo,Salary1.NetPayment);
    
        return(0);
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    struct Employee
    {
    ...
    };
    
    struct Salary
    {
    ...
    };

    Quzah.
    madusha likes this.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    You forgot to end your structs with ';'
    Code:
    struct Employee
    {
        char EmployeeName[20];
        int EmployeeNo;
        float BasicSalary,AllowanceRate,Deduction;
    };
    
    struct Salary
    {
        int SalaryNo;
        float NetPayment;
    };
    madusha likes this.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    2
    thanks alot ppl

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble returning a structure.
    By awr7126 in forum C Programming
    Replies: 7
    Last Post: 03-28-2011, 05:08 PM
  2. Replies: 4
    Last Post: 04-25-2010, 10:57 AM
  3. method returning a pointer to a structure
    By nacho4d in forum C++ Programming
    Replies: 3
    Last Post: 05-25-2009, 10:01 PM
  4. Problem with function returning a structure
    By SkaxCo in forum C++ Programming
    Replies: 2
    Last Post: 01-21-2007, 11:27 AM
  5. Returning the address of a member structure
    By cunnus88 in forum C++ Programming
    Replies: 4
    Last Post: 05-03-2006, 12:51 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21