Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Ground Controller Lvl 1
Message 1 of 2

can someone help me with my c++ program

Hi I currently working on my assignment and I have encountered some error can someone help me

 

#include <iostream>
#include <string>
using namespace std;

struct Employee
{
int eno;
string ename;
string position;
float bonus;
float salary;
};
int main()
{
Employee emp[10];//detail for 10 employee
cout<<"Please enter your detail"<<"\n";
for(int i =0; i<10; i++)

{
cout<<"Please enter your ID: ";
cin>>emp[i].eno;

cout<<"Please enter your name: ";
cin>>emp[i].ename;

cout<<"Please enter your job position: ";
cin>>emp[i].position;


cout << "\n";
cout << "---------- Employee Information -----------" << endl;
cout << "Employee ID: " << emp[i].eno << endl;
cout << "Employee Name: " << emp[i].ename << endl;
cout << "Job Position: " << emp[i].position << endl;
cout << "\n";
}

if(position == "Senior Lecturer")
{
cout << "Your salary is 6000 "<< endl;
}
else if(position == "Lecture")
{
cout << "Your salary is 5000 "<< endl;
}
else if(position == "Admin Assistant")
{
cout << "Your salary is 2500 "<< endl;
}
else
{
cout << "Your salary is 1500 "<< endl;
}
}

 

This is the error 

main.cpp: In function ‘int main()’:
main.cpp:38:8: error: ‘position’ was not declared in this scope
if(position == "Senior Lecturer")

1 Reply
Highlighted
Copilot Lvl 3
Message 2 of 2

Re: can someone help me with my c++ program

Please do your own homework assignments, or at the very least put it some place with proper syntax highlighting (also why is there no markdown support on here?)

 

You don't have `position` defined anywhere, `position` is a field in your `struct`. I'm assuming you want to place...

 

if(emp[i].position == "Senior Lecturer")
{
   cout << "Your salary is 6000 "<< endl;
}
else if(emp[i].position == "Lecture")
{
   cout << "Your salary is 5000 "<< endl;
}
else if(emp[i].position == "Admin Assistant")
{
   cout << "Your salary is 2500 "<< endl;
}
else
{
   cout << "Your salary is 1500 "<< endl;
}

 

Inside of the `for` loop and you meant to reference `emp[i]`.