I'm trying to build a beginner employee database program. Here is the problem; when counter "i" in main() becomes "1", the 1st line of the loop is skipped; in the other words, it doesn't wait for user to enter the value for "name" string. When I use "cin" rather than "gets" there is no problem...Why this is so? I use ubuntu 16.04.
#include <iostream>
#include <cstdio>
using namespace std;
void enter();
void report();
char name[2][30],salary[2][30];
int main()
{
int i;
for(i=0;i<2;i++){
cout<< "Name:"<<'\n';
gets(name[i]);
cout<< "Salary:"<<'\n'; cin>>(salary[i]);
}
report();
return 0;
}
void report()
{
int i;
cout<<"Name"<<'\t'<<"Salary"<<'\n';
for(i=0;i<2;i++){
cout<< name[i]<<'\t'<<salary[i]<<'\n';
}
}