Hi there
Just started an IT course recently, and although flying with HTML and other disciplines, I'm having trouble with some C++ syntax.
I have a problem with a short piece of code I have to write, which has to read input from the keyboard for 5 fictional employees, each of which has an ID number, name and salary. I have to use an array of structures, but the gets() piece of the code does not seem to work.
Looking at the code below, is it just my syntax that is wrong? I'm using C++ in Visual Studio 2008.
Many thanks in anticipation of some much-needed help!
#include <iostream>
#include <cstring>
using namespace std;
struct employees{
int id; /* employee ID */
char name[30]; /* employee name */
double salary; /* employee salary */
}employee[5];
int main(void)
{
int counter;
double salarytotal=0;
for(counter=0;counter<5;counter++)
{cout<<"Enter Employee ID number "<<counter+1<<": ";
cin>>employee[counter].id;
cout<<"Enter Salary for this Employee: ";
cin>>employee[counter].salary;
cout<<"Enter Name for this Employee (Max 30 chars): ";
gets(employee[counter].name);
salarytotal=salarytotal+employee[counter].salary;}
cout<<"Combined Salary for these five employees is: "<<static_cast<char>(156)<<salarytotal<<endl;
return 0;
}