Hello, i am new in c++ and just started to learn structures and this is the code i have been working on ->
(i want to make program in which user decide how many variables for struct to be entered along with their data)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include <iostream>
using namespace std;
struct employee
{
char name[30];
unsigned int age;
float salary;
};
int main()
{
int num;
cout <<"ENTER NO. OFF EMPPLOYEE O BE ENTERED";
cin >>num;
for(int emp=0;emp<=num;++emp)
{
employee emp;
cout <<"ENTER NAME OF EMPLOYEE- ";
cin >>name.emp;
cout <<"ENTER AGE OF EMPLOYEE- ";
cin >>age.emp;
cout <<"ENTER SALARY OF EMPLOYEE- ";
cin >>salary.emp;
}
return 0;
}
|
ERRORS:
C:\Users\lenovo\Desktop\c++\practice\test\main.cpp||In function 'int main()':|
C:\Users\lenovo\Desktop\c++\practice\test\main.cpp|16|error: redeclaration of 'employee emp'|
C:\Users\lenovo\Desktop\c++\practice\test\main.cpp|14|note: 'int emp' previously declared here|
C:\Users\lenovo\Desktop\c++\practice\test\main.cpp|18|error: 'name' was not declared in this scope|
C:\Users\lenovo\Desktop\c++\practice\test\main.cpp|20|error: 'age' was not declared in this scope|
C:\Users\lenovo\Desktop\c++\practice\test\main.cpp|22|error: 'salary' was not declared in this scope|
||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===|
So can anyone please help me ?
it's just that i don't understand what to do....