Structure Error

I am creating a program that displays the name and salary of the two employees however I do not know what is the code for the calculation of the salary in structures and when I compile this, it says "Invalid operands of types char [10] and char [10] to binary operator''. What code must be added or removed to make it work? Thank you

#include <iostream>
#include <stdlib.h>
#include <cstdio>
#include <conio.h>
#include <string>
using namespace std;


struct employee
{
char fullName [100];
char IDNumber [100];
char CompanyPosition [100];
char NumberHours [10];
char SalaryHour [10];
char MonthlySalary [20];
} profile [2], product ;


int main ()

{
int i;
for ( i = 0; i <= 1; i++) {
cout << "Enter your Full name: ";
gets (profile[i].fullName);
cout << "Enter your employee's ID number: ";
gets (profile[i].IDNumber);
cout << "Your Company Position: ";
gets (profile[i].CompanyPosition);
cout << "Your number of hours worked in 30 days: ";
gets (profile[i].NumberHours);
cout << "Salary per hour: ";
gets (profile[i].SalaryHour);
product.MonthlySalary = profile[i].NumberHours * profile[i].SalaryHour;
}

system ("PAUSE");
system("CLS");


for (i = 0; i <= 1; i++) {
cout << "Full name: ";
puts (profile[i].fullName);
cout << "Your Monthly Salary: ";
gets (profile[i].SalaryHour);
}
return 0;
}
Have a look at this example (and in future posts, please try to use the code tags).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

struct Example
{
    int some_value;
};

int main()
{
    Example instantiateTheStruct;
    /// If you have the object, you can use the values like this.
    instantiateTheStruct.some_value = 1;
    std::cout << "5 * some_value = " << (5*instantiateTheStruct.some_value) << std::endl;

    /// If you have a pointer to the struct, you can use the values like this
    Example* pointerToTheInstanceOfTheStruct = &instantiateTheStruct;
    std::cout << "5 * some_value = " << (5*pointerToTheInstanceOfTheStruct->some_value) << std::endl;
    return 0;
}
Before I use it to my program, I have tried the code you've given. I have added a program that inputs two numbers twice in a for loop and displays the answer each. However, it released an error. How to apply your code in looping? I do not know yet about the pointers. I did not studied it yet. Thank you

#include <iostream>
using namespace std;

struct Example
{
int some_value;
int value;
} product[2];

int main()
{
Example product;
/// If you have the object, you can use the values like this.
for (int i = 0; i <= 1; i++) {
cout << "Enter Value: ";
cin >> product[i].some_value;
cout << "Enter another value: ";
cin >> product[i].value ;
}
for (i = 0; i<= 1; i++) {
cout << (product.value[i]*product.some_value[i]) << endl;
}

return 0;
}
Last edited on
1
2
3
4
5
6
7
8
If you post something, please write your text like this. 
Subsequently place your code between code tags like this (but without the spaces):

[ code ]
    Your source code
[/ code]

It will make it easier for everyone to read your code.


As for your problem, when do you initialize product[0] and product[1]? As far as I can see those are two null-pointers. And you can't get any data from a null pointer.
I am first time in this forum and I do not know how to put in the form like that. How to put my code in that form?
Before your code type "code" in block-brackets and after your code type "/code" in block brackets.

Alternatively, paste your source code, select all your source code and click the "<>"-button on the right side of the window where you typed/pasted.
It was solved. I changed the gets() and puts () to cout and cin and made some changes. Now, It rans now the computation for the salary. Thanks for the help Nico

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <stdlib.h>
#include <cstdio>
#include <conio.h>
#include <string>
using namespace std;


struct employee
{
    char fullName [100];
    char IDNumber [100];
    char CompanyPosition [100];
    int NumberHours [10];
    int SalaryHour [10];
    char MonthlySalary [20];
} profile [2], product [2];


int main ()

{
    employee product;
    for ( int i = 1; i <= 2; i++)
    {
    cout << "\nEnter your Full name: ";   // Prompts the employee to enter his info
    cin >> profile[i].fullName;
    cout << "Enter your employee's ID number: ";
    cin >> profile[i].IDNumber;
    cout << "Your Company Position: ";
    cin >> profile[i].CompanyPosition;
    cout << "Your number of hours worked in 30 days: ";
    cin >> product.NumberHours[i];
    cout << "Salary per hour: ";
    cin >> product.SalaryHour[i];
}
system ("PAUSE");
system ("CLS");

for ( int i = 1; i <= 2; i++) {
  cout << "\nFull name: " << profile[i].fullName << endl;  // Displays the Full name and Salary
    cout << "Your Monthly Salary: ";
    cout << (product.SalaryHour[i]*product.NumberHours[i]) << endl;  // Computes the Salary
}
return 0;
}
Topic archived. No new replies allowed.