Error in Structures

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 is the mistake in the program ? 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;
}
Last edited on
The error
error: invalid operands of types 'char [10]' and 'char [10]' to binary 'operator*'

is coming up on this line.
product.MonthlySalary = profile[i].NumberHours * profile[i].SalaryHour;

You've defined these variables as character arrays and you can't multiple them with the * operator. Did you mean for these to be floats or doubles instead of strings?

char NumberHours [10];
char SalaryHour [10];
char MonthlySalary [20];

Even I change the declaration of NumberHours [10], SalaryHour [10], and MonthlySalary [20] from char to double or float, it still has an error. The members are in char and how I will declare them into double without error to be able to calculate? Can you tell me what code need to be added or changed? Thank you
Last edited on
Declare doubles...

1
2
3
double NumberHours;
double SalaryHour;
double MonthlySalary;


I'm not sure I understand why product is a separate instance of the employee struct. It looks like you intend to print out the monthly salary for each employee in the last for loop. Do you want to store their monthly salary in the same employee structure that holds all their other info?

for example,
profile[i].MonthlySalary = profile[i].NumberHours * profile[i].SalaryHour;

then at the end, print out profile[i].MonthlySalary instead of profile[i].SalaryHour?

1
2
3
4
5
6
for (i = 0; i <= 1; i++) {
cout << "Full name: ";
puts (profile[i].fullName);
cout << "Your Monthly Salary: ";
gets (profile[i].SalaryHour);
}
Topic archived. No new replies allowed.