Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
there are the messages

MSIL
Compiling NONAME00.CPP:
Error NONAME00.CPP 25: Undefined symbol 'income' in function main()
Error NONAME00.CPP 42: Expression syntax in function main()
Error NONAME00.CPP 57: If statement missing ) in function main()



this is my program

#include<stdio.h>
struct income_information{
  float Basic_salary;
  float overtime;
};

struct record{
  int id,number;
  char *starting_time;
  char *name;

  struct income_information income;

}worker[5];

main()
{

  income.Basic_salary;
  income.overtime;

  for(int i=0;i<5;i++)
  {
    printf("Worker[i]\n name: ");
    scanf(" %s",&income.name[i]);
    printf("ID number:");
    scanf("%d",&income.id[i]);
    printf("contact number:");
    scanf("%d",&income.number[i]);
    printf("starting date:");
    scanf(" %c",&income.starting_time[i]);
    printf("Basic Salary:");
    scanf("%f",&income.Basic_salary[i]);
    printf("over itme:");
    scanf("%f",&income.overtime[i]);
    if(20=>income.overtime[i]=<39)
    {
      printf("The Balance = %.2f",income.Basic_salary[i]*2.50);
    }
    else
    if(40>=>income.overtime[i]=<49)
    {
      printf("The Balance = %.2f",income.Basic_salary[i]*4.2);
    }
    else
    if(50=>income.overtime[i]=<60)
    {
      printf("The Balance = %.2f",income.Basic_salary[i]*5);
    }

    printf("Deduction: \tKWSP = %f \t\tsocso =    %f",income.Basic_salary[i]/11,income.Bas…
}

return i;




when i want to compiler it at c++ turbo it shows to me 3 errors. .i couldn't fix that errors

tell me how??
Posted
Updated 29-Dec-10 6:48am
v6
Comments
voloda2 29-Dec-10 11:33am    
improved readability.

What are the errors? No one can help you without more details
Manfred Rudolf Bihy 29-Dec-10 11:58am    
@Voloda2: I second that!
Manfred Rudolf Bihy 29-Dec-10 12:21pm    
Hi Mohamed, I just read your code again and found some more things that seem to have gone wrong:
- The first two lines in your main function don't belong there.
- The variable inside the for loop called income isn't defined, but from your code I guess you should have used "worker" instead as it is an array of structs and in your for loop you're indexing income with [] so it should be "worker" instead of "income". OK?
Example line:
scanf(" %s",&worker[i].name);
Do you understand what I'm trying to tell you?
Mohammed Abdulqawi Alhumaikani 29-Dec-10 12:25pm    
i semi couldn't get ur idea .. but if u can correct my codes and send it back ..
Manfred Rudolf Bihy 29-Dec-10 12:56pm    
We're here to help you, but please understand that I don't want to do your work. So tell me, which part of my explanation is causing you problems? I'll try my best to guide you :)
"worker" is declared as an array of structs. To access an array you have to index it with []. Then to get at what is inside the struct you use the ".". The & operator gets the address of an object which is needed for the function scanf as it needs a pointer as a parameter.
So this line:
scanf(" %s",&worker[i].name);
reads the input from your keyboard into the name field of the ith worker struct in the array.
Sorry, can't get it any clearer :)

You should carefully read the error messages, they are usually pretty informative. If after reading them you're still stuck, please post them here.
:)
 
Share this answer
 
One thing I can spot straight away is the last line inside the main function of your code. The line is incomplete and ends with a strange character that looks like an ellipse. If it looks that way in your code I wouldn't be surprised there are errors.

I too agree with voloda2 that the least you could do is to provide as with the full details of the errors the compiler threw at you.

Regards,

Manfred
 
Share this answer
 
you have all kinds of issues with your code and it shows a lack of basic understanding of coding. If you are taking a class, you need to show this code to your teacher or get a tutor. If you aren't taking a class, then take one!

You clearly do not understand object-oriented programming. In this style of programming, you are dealing with objects, say for instance a house. Now, that house can have rooms. And it can have any number of rooms. Those rooms can have furniture...all different kinds of furniture. And that furniture can have different properties, such as fabric, color, size, etc...

This is what you're doing here. First, you're creating two new types of objects, income_information and record. The struct keyword tells the compiler that you are creating a new object type. Right away, though, you define income_information (using the struct keyword), then you define record and then define a new object within record, also called income_information.

You don't use the struct keyword when you are trying to add an object to another.

In your case, record should just be:

C++
struct record
{
  int id, number;
  char *starting_time;
  char *name;
  income_information income;
}worker[5]


But then, you are trying to access income without first accessing the record you are dealing with. income is an object within another object, so you first have to access its parent.

That's why you are getting that first error.

Then, you write income.name. income is an income_information type which has no property called name.

As to the first two lines in your main section, like others have said, they do nothing.

You need to first access each worker object and then set the properties of that worker.

You also don't understand pointers. If you are brand new to programming, you shouldn't be using pointers at all. They will just confuse you. And in this case, you don't need them. Without the pointers, you could access a worker's name like:
C++
worker[0].name = "Jack Bauer"


To access basic salary of a worker, you would want
C++
worker[0].income.Basic_salary = 12.50;


And, you have your comparators screwed up in your if statements. You switched the less than or greater than signs with the equal signs.

It should be:
C++
if(i<=15)


Also, you can't do a double comparison the way you did, you need to use the && comparator.

For instance, if you write:
C++
int i = 5;
if (3<=i<=2)
{
  cout << "shouldn't get here";
}

you will get the message, even though 5 is not less than or equal to 2.

The reason for this is that it will evaluate the first part of the comparison (3<=i). This will return true. true has an integer value of 1. So, then it evaluates the second part which would be true<=2. Since true = 1, true is less than or equal to 2.

It should be
C++
if (3<=i && i<=2)




Seriously, take a class or get a tutor.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 29-Dec-10 16:07pm    
Whilst you have the complete answer showing all of his mistakes (thus my 5+), I am opposed to the bashing you're dealing out here.
Take it easy! :)
do u mean after editing will be like this


C#
#include<stdio.h>
struct income_information
{
  float Basic_salary;
  float overtime;
};
struct record
{
  int id,number;
  char *starting_time;
  char *name;
  struct income_information income;
}worker[5];

main()
{
  income.Basic_salary;
  income.overtime;
  for(int i=0;i<5;i++)
  {
    printf("Worker[i]\n name: ");
    scanf(" %c",income.name[i]);
    printf("ID number:");
    scanf("%d",&income.id[i]);
    printf("contact number:");
    scanf("%d",&income.number[i]);
    printf("starting date:");
    scanf(" %c",income.starting_time[i]);
    printf("Basic Salary:");
    scanf("%f",&income.Basic_salary[i]);
    printf("over itme:");
    scanf("%f",&income.overtime[i]);
    if(20=>income.overtime[i]=<39)
    {
      printf("The Balance = %.2f",income.Basic_salary[i]*2.50);
    }
    else
      if(40>=>income.overtime[i]=<49)
      {
        printf("The Balance = %.2f",income.Basic_salary[i]*4.2);
      }
      else
        if(50=>income.overtime[i]=<60)
        {
          printf("The Balance = %.2f",income.Basic_salary[i]*5);
         }
    printf("Deduction:  \tKWSP = %f \t\tsocso = %f",income.Basic_salary[i]/11,income.Basic_salary[i]/3);
  }
  return i;
}




but still shows me the same errors ..
 
Share this answer
 
v2
Comments
Orcun Iyigun 29-Dec-10 15:09pm    
although you fix them your if statements are now proper yet.. if (3<=i && i<=2) as William said you have to split the conditions.. if overtime income more or equal to 40 and overtime income less than or equal to 49.. and tehn do the action.

if(40>=>income.overtime[i]=<49) you used two ">" two times after 40. maybe you should carefully review your code again.

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