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:
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:
worker[0].name = "Jack Bauer"
To access basic salary of a worker, you would want
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 sign
s with the equal signs.
It should be:
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:
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
if (3<=i && i<=2)
Seriously, take a class or get a tutor.