Problem with struct (scope not declared)

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....
See, the error output is quite clear, you've redeclared the variable 'emp'.
Try change the name of any of the two 'emp's.

And, when using the member in the struct, put the member name AFTER the dot.
AH! my bad 'liuyang' i just didn't saw it but gee thanks!!! i finally got it to work!!!:)
#include <iostream>
using namespace std;
struct employee
{
char name[30];
unsigned int age;
float salary;
};
int main()
{
int num;
cout <<"ENTER NO. OF EMPLOYEE TO BE ENTERED";
cin >>num;
for(int emp=0;emp<=num;++emp)
{
employee emp1;
cout <<"ENTER NAME OF EMPLOYEE- ";
cin >>emp1.name;
cout <<"ENTER AGE OF EMPLOYEE- ";
cin >>emp1.age;
cout <<"ENTER SALARY OF EMPLOYEE- ";
cin >>emp1.salary;
}
return 0;
}

the finished product :)
Topic archived. No new replies allowed.