Question #186030

Create a structure called employee that contains two members: an employee

number (type int) and the employee’s compensation (in dollars; type float). Ask the

user to fill in this data for three employees, store it in three variables of type struct

employee, and then display the information for each employee.


Expert's answer

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


//Create a structure called employee that contains two members: an employee
//number (type int) and the employee’s compensation (in dollars; type float). 
struct Employee{
	 int number;
	 float compensation;
};


int main(){  
	struct Employee employee[3];
	//Ask the user to fill in this data for three employees store it in three variables of type struct employee
	for(int i=0;i<3;i++){
		cout<<"Enter the employee number "<<(i+1)<<": ";
		cin>>employee[i].number;
		cout<<"Enter the employee compensation "<<(i+1)<<": ";
		cin>>employee[i].compensation;
		cout<<"\n";
	}
	//display the information for each employee.
	cout<<"\n";
	for(int i=0;i<3;i++){
		cout<<"The employee number "<<(i+1)<<": "<<employee[i].number<<"\n";
		cout<<"The employee compensation "<<(i+1)<<": "<<employee[i].compensation<<"\n";
	}


	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS