what is wrong with the code?

what is wrong with the code?
#include <iostream.h>
struct Employee
{
int empno;
char name;
char dept;
int salary;
char category;
}emp;
void main()
{
cout<<"enter employee no";
cin>>emp.empno;
cout<<"enter employee name";
cin>>emp.name;
cout<<"enter the dept:";
cin>>emp.dept;
cout<<"enter salary";
cin>>emp.salary;

if(emp.salary>>4000)
emp.category='A';
else
emp.category='B';

cout<<"the employee is" ;
cout<< emp.name;
cout<<emp.dept;
cout<<emp.salary;
cout<<emp.category;
}

if(emp.salary>>/*'>'?*/4000)
thanx
it says declaration syntax error
#include <iostream.h>
struct Employee
{
int empno;
char name;
char dept;
int salary;
char category;
}emp;
void main()
{
cout<<"enter employee no";
cin>>emp.empno;
cout<<"enter employee name";
cin>>emp.name;
cout<<"enter the dept:";
cin>>emp.dept;
cout<<"enter salary";
cin>>emp.salary;

if(emp.salary>4000)
emp.category='A';
else
emp.category='B';

cout<<"the employee is" ;
cout<< emp.name;
cout<<emp.dept;
cout<<emp.salary;
cout<<emp.category;
}



#include <iostream.h>

and btw, use code tag will ya... :D
i use pre standard C++
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
26
27
28
29
30
31
32
33
#include <iostream>

using namespace std;
struct Employee
{
int empno;
char name;
char dept;
int salary;
char category;
}emp;
void main()
{
cout<<"enter employee no";
cin>>emp.empno;
cout<<"enter employee name";
cin>>emp.name;
cout<<"enter the dept:";
cin>>emp.dept;
cout<<"enter salary";
cin>>emp.salary;

if(emp.salary>4000)
emp.category='A';
else
emp.category='B';

cout<<"the employee is" ;
cout<< emp.name;
cout<<emp.dept;
cout<<emp.salary;
cout<<emp.category;
}
soory shows un expected results
i guess i figured out why:

1
2
3
4
5
6
7
8
9
10
char name;
char dept;
int salary;
//...
cout<<"enter employee name";
cin>>emp.name;
cout<<"enter the dept:";
cin>>emp.dept;
cout<<"enter salary";
cin>>emp.salary;


understand? (i'm a little bit lazy to write)
just explain pls a bit
I fixed the code. If you have any questions please fell free to ask. I made it look nice too, but you can fix that to your liking.

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
26
27
28
29
30
31
32
33
34
#include <iostream.h>
#include  <conio.h>
struct Employee
{
char empno[100];
char name[100];
char dept[100];
int  salary;
char category[1];
}emp;

void main()
{
cout<<"Enter employee no:\n";
cin.getline(emp.empno,100);
cout<<"Enter employee name:\n";
cin.getline(emp.name,100);
cout<<"Enter the dept:\n";
cin.getline(emp.dept,100);
cout<<"Enter salary:\n";
cin>>(emp.salary);

if(emp.salary>4000)
{emp.category[0]='A';}
else
{emp.category[0]='B';}
clrscr();
cout<<"The employee is: ";
cout<<emp.name<<endl;
cout<<"Department: "<<emp.dept<<endl;
cout<<"Salary: "<<emp.salary<<endl;
cout<<"Category "<<emp.category<<endl;
getch();
}
tHANX A LOT GUATEMALA007 WHATS THE USEE OF
CIN.GETLINE??
Last edited on
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
26
27
28
29
30
31
32
33
34
35
36
#include <iostream.h>
#include  <conio.h>
struct Employee
{
char empno[100];
char name[100];
char dept[100];
int  salary;
char category[1];
}emp;

void main()
{
cout<<"Enter employee no:\n";
cin.getline(emp.empno,100);
cout<<"Enter employee name:\n";
cin.getline(emp.name,100);
cout<<"Enter the dept:\n";
cin.getline(emp.dept,100);
cout<<"Enter salary:\n";
cin>>(emp.salary);

if(emp.salary>4000)
{emp.category[0]='A';}
else
{emp.category[0]='B';}
clrscr();
cout<<"The employee is: ";
cout<<emp.name<<endl;
cout<<"Department: "<<emp.dept<<endl;
cout<<"Salary: "<<emp.salary<<endl;
cout<<"Category "<<emp.category<<endl;
getch();
} 
 
 
Oh sorry didn't realize i used it, but its just so if you input spaces or blank characters into the response the computer actually includes them in the output. Normally if you entered a name followed by a space then a last name everything after the space would be ignored, but with cin.getline(); the whole input is incorporated into the char array.
any ways thanx @guatemala007
no problem
Topic archived. No new replies allowed.