Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
guys, i was making a employee project using classes and arrays and used loops and two functions, but when i am running it it is showing me an many errors i dont know whats wrong in this code
this is my code:


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

class employee //class of employee
{
  int id;      //id of a employee
  int salary;  //salary of a employee
  string name; //name of employee

public:
  void setid(void) //function to set id of employee
  {
    cout << "enter the name of a employee :\n";
    cin >> id << name;
    cout << "enter the id of a employee :\n";
    cin >> id << endl;
    cout << "enter the salary of a employee :\n";
    cin >> salary << endl
                  << endl;
  }

  void display(void) //to display a data of employee.
  {
    cout << "the name of employee is:" << name;
    cin >> id << endl;
    cout << "id of this employee is: " << id;
    cin >> id << endl;
    cout << "salary of this employee is: " << id;
    cin >> salary << endl;
  }
};

int main()
{
  employee all[4]; //creating array to store 4 employee
  for (int i = 0; i < 4; i++)
  {
    all[i].setid();
    all[i].display();
  }

  return 0;
}


What I have tried:

i have tried to solve 2,3 error which were easy but unable to solve that operands error of<<;
Posted
Updated 10-Jul-21 4:35am

1 solution

You haven't specified your errors, so we have to look for them. Not nice.

But
C++
cin >> id << name;
makes no sense. cin can only be followed by >>. The << is junk that will cause a compile error. That's not the only one of these. You also have a lot of << endl after cin. Take them out.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900