Oct 5, 2013 at 10:06pm UTC
The << doesn't know how to handle Contracter[x]
Edit: noticed some more problems.
for (int out=0;out<3;)
this is an infinite loop. should be for (int out=0;out<3; out++)
also there are no {}
so all this loop does is repeat cout<<"HR Management\n" ;
three times.
this statement if (corf=1)
should be if (corf==1)
Last edited on Oct 5, 2013 at 10:24pm UTC
Oct 5, 2013 at 10:09pm UTC
So how would I let it know to print the number? I have this problem 3 more times in the my program.
Any example I could learn from?
What should I do to get it to work?
Oct 5, 2013 at 10:38pm UTC
The << operator knows how to handle integers, doubles, characters, and stirngs so you just need to give it one of those.
cout<<"There are " <<Contracter[x]<<" Contract Employee's\n" ;
could be
cout<<"There are " << x << Contract Employee's\n";
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#include<iostream>
#include<string>
using namespace std;
struct employee
{ string Firstn;
string Lastn;
int IDn;
string Gender;
int Salary;
};
employee Fulltime[500], Contracter[500];
int main()
{//1
int x=0;
int z=0;
int choice;
for (int out=0;out<3; out++)
{
cout<<"HR Management\n" ;
cout<<"-------------\n\n" ;
cout<<"(1) Add New Employee\n" ;
cout<<"(2) Print All Employees\n" ;
cout<<"(3)Quit\n" ;
cin>>choice;
cin.ignore();
cout<<choice;
if (choice==1)
{//2
int corf;
cout<<"For New Contract Employee, Press 1\n" ;
cout<<"For New Full Time Employee, press 2\n" ;
cin>>corf;
if (corf == 1)
{//3
cout<<"Contracter Form\n" ;
cout<<"----------------\n" ;
cout<<"Employee's First name?\n" ;
cin>>Contracter[x].Firstn;
cout<<"Employee's Last name?\n" ;
cin>>Contracter[x].Lastn;
cout<<"Employee's ID Number?\n" ;
cin>>Contracter[x].IDn;
cout<<"Employee's Gender?\n" ;
cin>>Contracter[x].Gender;
cout<<"Employee's Salary?\n" ;
cin>>Contracter[x].Salary;
x++; } //3
else if (corf == 2)
{//4
cout<<"Fulltime Form\n" ;
cout<<"----------------\n" ;
cout<<"Employee's First name?\n" ;
cin>>Fulltime[z].Firstn;
cout<<"Employee's Last name?\n" ;
cin>>Fulltime[z].Lastn;
cout<<"Employee's ID Number?\n" ;
cin>>Fulltime[z].IDn;
cout<<"Employee's Gender?\n" ;
cin>>Fulltime[z].Gender;
cout<<"Employee's Salary?\n" ;
cin>>Fulltime[z].Salary;
z++;
}//4
}//2
else if (choice == 2)
{//5
cout<<"There are " << x <<" Contract Employee's\n" ; //Error Here.
for (int y=0; y < x; y++)
{//6
cout<<"First Name: " <<Contracter[y].Firstn;
cout<<"\nLast Name: " <<Contracter[y].Lastn;
cout<<"\nID Number: " <<Contracter[y].IDn;
cout<<"\nGender: " <<Contracter[y].Gender;
cout<<"\nSalary: " << Contracter[y].Salary << endl << endl;
}//6
cout<<"There are " << z <<" Full Time Employee's" << endl;
for (int w = 0; w < z; w++)
{//7
cout<<"First Name: " <<Fulltime[w].Firstn;
cout<<"\nLast Name: " <<Fulltime[w].Lastn;
cout<<"\nID Number: " <<Fulltime[w].IDn;
cout<<"\nGender: " <<Fulltime[w].Gender;
cout<<"\nSalary: " << Fulltime[w].Salary << endl << endl;
}//7
}//5
}
cin.ignore();
return 0;
}
Last edited on Oct 5, 2013 at 10:43pm UTC
Oct 5, 2013 at 10:47pm UTC
Why the cin.ignore()? Whats that do?
Also I now when I run my code When I add in a new person it quits after salary.
EDIT: the whole menu actually gives incorrect responses.
EDIT 2:It runs Fine now but it prints whats in contracter/fulltime[0]
So it prints
example
There are 2 contracters
First Name: gfdgdf
Last Name: fdsfs
ID Number: gffdgfd
Gender: gfdgfdgfd
Salary: gfdgfdg
//problem here and it also does this for fulltime
First Name: 0
Last Name: 0
ID Number:0
Gender: 0
Salary: 0
Code incoming
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
#include<iostream>
#include<string>
using namespace std;
struct employee
{ string Firstn;
string Lastn;
int IDn;
string Gender;
int Salary;
};
employee Fulltime[500], Contracter[500];
int main()
{//1
int x=1;
int z=1;
int choice;
int corf;
for (int out=0;out<3;)
{
cout<<"HR Management\n" ;
cout<<"-------------\n\n" ;
cout<<"(1) Add New Employee's\n" ;
cout<<"(2) Print All Employees\n" ;
cout<<"(3)Quit\n" ;
cin>>choice;
if (choice==1)
{//2
cout<<"For New Contract Employee, Press 1\n" ;
cout<<"For New Full Time Employee, press 2\n" ;
cin>>corf;
if (corf==1)
{//3
cout<<"Contracter Form\n" ;
cout<<"----------------\n" ;
cout<<"Employee's First name?\n" ;
cin>>Contracter[x].Firstn;
cout<<"Employee's Last name?\n" ;
cin>>Contracter[x].Lastn;
cout<<"Employee's ID Number?\n" ;
cin>>Contracter[x].IDn;
cout<<"Employee's Gender?\n" ;
cin>>Contracter[x].Gender;
cout<<"Employee's Salary?\n" ;
cin>>Contracter[x].Salary;
x++; } //3
else if (corf==2)
{//4
cout<<"Fulltime Form\n" ;
cout<<"----------------\n" ;
cout<<"Employee's First name?\n" ;
cin>>Fulltime[z].Firstn;
cout<<"Employee's Last name?\n" ;
cin>>Fulltime[z].Lastn;
cout<<"Employee's ID Number?\n" ;
cin>>Fulltime[z].IDn;
cout<<"Employee's Gender?\n" ;
cin>>Fulltime[z].Gender;
cout<<"Employee's Salary?\n" ;
cin>>Fulltime[z].Salary;
z++;
}//4
}//2
else if (choice==2)
{//5
cout<<"There are " <<x<<" Contract Employee's\n" ;
for (int y=1;y<=x;y++)
{//6
cout<<"First Name: " <<Contracter[y].Firstn;
cout<<"\nLast Name: " <<Contracter[y].Lastn;
cout<<"\nID Number: " <<Contracter[y].IDn;
cout<<"\nGender: " <<Contracter[y].Gender;
cout<<"\nSalary: " <<Contracter[y].Salary;
cout<<"\n\n" ;
}//6
cout<<"There are " <<z<<" Full Time Employee's\n" ;
for (int w=1;w<=z;w++)
{//7
cout<<"First Name: " <<Fulltime[w].Firstn;
cout<<"\nLast Name: " <<Fulltime[w].Lastn;
cout<<"\nID Number: " <<Fulltime[w].IDn;
cout<<"\nGender: " <<Fulltime[w].Gender;
cout<<"\nSalary: " <<Fulltime[w].Salary;
cout<<"\n\n" ;
}//7
}//5
if (choice==3)
{return 0;
}//1
}
system("pause" );
cin.ignore();
return 0;
}
Last edited on Oct 5, 2013 at 11:43pm UTC
Oct 6, 2013 at 1:07am UTC
Never Mind I got it on my own thank you :)