I am trying to output the all of the information provided but i can only output the final output entered a set of times.I am pretty new to loops
#include <iostream>
#include <string>
using namespace std;
int sized = 0;
//Global array declaration
Employee Array [60]:
//Struct declaration
struct Employee
{
string name;
int age;
double salary;
};
//Protype
void Showinfo(Employee);
int main()
{
//Declaring a variable of type Employee
Employee Emp;
cout << "Enter the number of employees you want to enter into the database: ";
cin >> sized;
cout << endl << endl;
system("cls");
//Getting the name of the Employee
for (int i = 0; i < sized; i++)
{
cout << "Enter Full name of employee: ";
cin.ignore();
getline(cin, Emp.name);
cout << endl;
cout << "Enter age of employee: ";
cin >> Emp.age;
cout << endl;
cout << "Enter salary of employee: ";
cin >> Emp.salary;
cout << endl;
system("cls");
}
// To display the elements of the information given
cout << endl << "Displaying Information." << endl;
cout << "--------------------------------" << endl;
for (int i = 0; i < sized; i++)
{
Showinfo(Emp);
}
cin.ignore();
return 0;
}
//To display/showcase the information received
void Showinfo(Employee Emp)
{
cout << "Name: " << Emp.name << endl;
cout << "Age: " << Emp.age << endl;
cout << "Salary: " << Emp.salary << endl << endl;
}
The expected outcome is like
Inputs by the user***
Enter the no of information to be stored: 2
Enter Name:ball
Enter age:69
Enter wage:420
Enter Name:Rally
Enter age:42
Enter wage:690000
Expected output: Displaying information ------------------------- Name:ball
age:69
wage:420
Name:Rally
age:42
wage:690000
My output Displaying Information
Name:Rally
age:42
wage:690000
Name:Rally
age:42
wage:690000
So basically my program outputs the final set of information received * Sized number of times