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;
}

Your code is looking ok for a strapping young coder. I think your problem lies here:

display_Desig  == "Labor";

Here you're trying to compare, not assign. Use only one = to assign. Which raises even more questions, I'm not sure if you should try to assign a string into a character variable.

Your code is looking ok for a strapping young coder. I think your problem lies here:

display_Desig  == "Labor";

Here you're trying to compare, not assign. Use only one = to assign. Which raises even more questions, I'm not sure if you should try to assign a string into a character variable.

Thank you Topi Ojala for your reply.

I tried that earlier before i posted using single =. But then i got this : error: invalid conversion from ‘const char*’ to ‘char.

Yes, that's what I meant in the later part of my post. You're trying to assign a string (aka const char*) "Labor" into a char variable display_Desig. Obviously that won't work.

Easiest solution would be to declare the variable as string.

Yes, that's what I meant in the later part of my post. You're trying to assign a string (aka const char*) "Labor" into a char variable display_Desig. Obviously that won't work.

Easiest solution would be to declare the variable as string.

I have not reached strings yet. But will go thru them and see how i can manipulate what. I wish someone introduced me to coding this part using string with some sort of code as example. Thank you anyways for your help Mr. Ojala

Can anyone please correct / improve / modify the incorrect code above and post it back so that when it compiles it prints the designation for each case. Thanks

Change the type of display_Desig at a pointer to char, char *. And with the single equal sign for assignment, it should fix the compilation error.

For the rest, there at least two small things to change / add:
1. change the type of all those B_SAL, H_ALLOW... variables to float (or double), since they hold floating-point values.
2. add a line "cin.ignore();" at the end of the loop, just after "cin >> repeat". This is due to the fact that since you read only a single character, the rest of the user input will be left dangling on the input stream and repeating the loop might yield undesirable effects. You can try without that line to see what happens.

All-in-all, it's quite a good beginning!

Change the type of display_Desig at a pointer to char, char *. And with the single equal sign for assignment, it should fix the compilation error.

For the rest, there at least two small things to change / add:
1. change the type of all those B_SAL, H_ALLOW... variables to float (or double), since they hold floating-point values.
2. add a line "cin.ignore();" at the end of the loop, just after "cin >> repeat". This is due to the fact that since you read only a single character, the rest of the user input will be left dangling on the input stream and repeating the loop might yield undesirable effects. You can try without that line to see what happens.

All-in-all, it's quite a good beginning!

Thank you Mr. Mike. I will try your suggestion.

Change the type of display_Desig at a pointer to char, char *. And with the single equal sign for assignment, it should fix the compilation error.

For the rest, there at least two small things to change / add:
1. change the type of all those B_SAL, H_ALLOW... variables to float (or double), since they hold floating-point values.
2. add a line "cin.ignore();" at the end of the loop, just after "cin >> repeat". This is due to the fact that since you read only a single character, the rest of the user input will be left dangling on the input stream and repeating the loop might yield undesirable effects. You can try without that line to see what happens.

All-in-all, it's quite a good beginning!

Mr. Mike, I tried your suggestion by converting the int variables on top to double first and then float and also included cin.ignore() below cin.repeat. When compiled, i still keep getting the following error (invalid conversion from 'const char*' to 'char').

Hurray! I got it. Besides what Mike suggested, one more correction I had to do was convert the variable type of 'display_Desig' to String (as Mr. Ojala had suggested in his second post). It worked and compiles without any error now.

Thank you both, Mr. Ojala and Mr. Mike for your help. You guys were great.
Looking forward to posting more questions as i progress in my lessons.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.