Hi all,
I am totally new to C++. I began learning C++ some 2-3 months back referring to youtube tutorial channels and now by reading a book by Robert Lafore. I practice when i get free time. I still have long way to go.
Well, referring to some examples that i learned and some ideas of my own, i wrote this code (Please don't laugh :). It could be the worst code ever written. I am learning.
When i compile this (and i am using GCC on Linux), i get this error : C++ forbids comparison between pointer and integer
.
I know this has got something to do with calling the integer value and passing a string value to it. Can someone please explain to me how i can correct this code so that it can be compiled.
Thank you all in advance.
#include <iostream>
#include <cstdlib> // for system clear
#include <iomanip> // for setw
using namespace std;
void starline(char, int); // Function Definition
int main()
{
char Emp_FName[15], Emp_LName[15];
int Emp_Desig_Code;
char display_Desig; // To display Designation based on Emp_Desig code
int B_Sal, F_Allow, C_Allow, H_Allow;
float Total;
char repeat;
do
{
system ("clear");
cout << "\nEnter Employee First Name : ";
cin >> Emp_FName;
cout << "Enter Employee Last Name : ";
cin >> Emp_LName;
cout << "\nChoose Employee Designation by selecting a number from the below list: ";
cout << "\n1) Labor" << "\n2) Carpenter" << "\n3) Painter" << "\n4) Welder"
<< "\n5) Mason" << "\n6) Driver" << "\n7) A/c Technician" << "\n8) Electrician"
<< "\n9) Fabricator" << "\n10) Supervisor" << "\n11) General Supervisor" << "\n12) Assistant Engineer"
<< "\n13) Senior Engineer" << "\n14) Project Manager" << "\nEnter no. here > " ;
cin >> Emp_Desig_Code;
cout <<"\n";
starline('*',40);
switch (Emp_Desig_Code)
{
case 1:
// If designation is Labor"
display_Desig == "Labor";
B_Sal = 100.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.00);
H_Allow = ((float)B_Sal * 0.20);
break;
case 2:
// If designation is Carpenter";
display_Desig == "Carpenter";
B_Sal = 120.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.00);
H_Allow = ((float)B_Sal * 0.20);
break;
/* case 3:
// If designation is Painter";
display_Desig == "Painter";
B_Sal = 130.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.00);
H_Allow = ((float)B_Sal * 0.20);
break;
case 4:
// If designation is Welder";
display_Desig == "Welder";
B_Sal = 150.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.00);
H_Allow = ((float)B_Sal * 0.20);
break;
case 5:
// If designation is Mason";
display_Desig == "Mason";
B_Sal = 175.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.00);
H_Allow = ((float)B_Sal * 0.20);
break;
case 6:
// If designation is Driver";
display_Desig == "Driver";
B_Sal = 200.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.00);
H_Allow = ((float)B_Sal * 0.20);
break;
case 7:
// If designation is A/C Technicianr";
display_Desig == "A/C Technician";
B_Sal = 225.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.00);
H_Allow = ((float)B_Sal * 0.20);
break;
case 8:
// If designation is Electrician";
display_Desig == "Electrician";
B_Sal = 225.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.15);
H_Allow = ((float)B_Sal * 0.20);
break;
case 9:
// If designation is Fabricator";
display_Desig == "Fabricator";
B_Sal = 250.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.15);
H_Allow = ((float)B_Sal * 0.20);
break;
case 10:
// If designation is Supervisor";
display_Desig == "Supervisor";
B_Sal = 300.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.15);
H_Allow = ((float)B_Sal * 0.20);
break;
case 11:
// If designation is General Supervisor";
display_Desig == "General Supervisor";
B_Sal = 325.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.15);
H_Allow = ((float)B_Sal * 0.20);
break;
case 12:
// If designation is Assistant Engineer";
display_Desig == "Assistant Engineer";
B_Sal = 500.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.15);
H_Allow = ((float)B_Sal * 0.20);
break;
case 13:
// If designation is Senior Engineer";
display_Desig == "Senior Engineer";
B_Sal = 600.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.15);
H_Allow = ((float)B_Sal * 0.20);
break;
case 14:
// If designation is Project Manager";
display_Desig == "Project Manager";
B_Sal = 750.00;
F_Allow = ((float)B_Sal * 0.10);
C_Allow = ((float)B_Sal * 0.15);
H_Allow = ((float)B_Sal * 0.20);
break;*/
default:
cout << "\nUnknown!";
}
//************************************
cout << "\n";
starline ('-',40);
cout << "\nEmployee Details as follows:\n";
starline ('-',40);
cout << setw(15) << "\nEmployee Name : " /*<< setw(15) */<< Emp_FName << " " /*<< setw(15) */<< Emp_LName;
//trades_defined();
cout << "\nDesignation : " << display_Desig;
cout << setw(15) << "\nBasic Salary : " << setw(15) << (float)B_Sal;
cout << setw(15) << "\nFood Allowance : " << setw(15) << (float)F_Allow;
cout << setw(15) << "\nCar Allowance : " << setw(15) << (float)C_Allow;
cout << setw(15) << "\nHousing Allowance : " << setw(15) << (float)H_Allow;
Total = ((float)B_Sal + (float)F_Allow + (float)C_Allow + (float)H_Allow);
cout << setw(15) << "\nTotal Gross Salary : " << setw(15) << (float)Total;
cout << "\n\nDo you want to enter another record (y/n) : ";
cin >> repeat;
}
while (repeat == 'y' || repeat == 'Y');
}
//************************************
void starline (char ch, int n)
{
for (int j=0; j<n; j++)
cout << ch;
}