Jan 16, 2011 at 4:56am UTC
I need to sort the netpays in ascending order and am really lost. Can you guys give me a nudge in the right direction?
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int MAX = 100;
main() {
char employeeid [100][12];
char firstname [100][10], lastname [100][15], ms[100];
int hoursworked [100];
double grosspay[100], netpay[100], numbers[100], table[100], hourlyrate[100], taxrate[100], taxamount[100],overtimepay[100], overtimehours[100],regularpay[100],averageofnetpay[100],sumofnetpay, numberofemployees[100] ;
int counter = 0;
int i, n;
ifstream fin("employee3.in");
while(fin>>employeeid[counter]>>hoursworked[counter]>>hourlyrate[counter]>>ms[counter]>>firstname[counter]>>lastname[counter])
counter=counter+1;
for (i=0; i<counter; i++){
if(hoursworked[i] > 40) {
overtimehours[i] = hoursworked[i] - 40;
overtimepay[i] = overtimehours[i] * hourlyrate[i]*1.5;
regularpay[i]= hourlyrate[i] * 40; }
else{
overtimehours[i] = 0;
overtimepay[i] = 0;
regularpay[i] = hoursworked[i] * hourlyrate[i];}
}//for
for (i=0; i<counter; i++){
grosspay[i]=regularpay[i] + overtimepay[i];}// end grosspay loop
for (i=0; i<counter; i++){
if(grosspay[i]>1000)taxrate[i] = .3;
else if(grosspay[i]> 800) taxrate[i] = .2;
else if(grosspay[i]> 500) taxrate[i] = .1;
else taxrate[i] = 0;
if (ms[i]=='S') taxrate[i]=(taxrate[i]+.05);
else if (ms[i]=='s') taxrate[i]=(taxrate[i]+.05);
else if ((ms[i]=='H') && (grosspay[i]>500)) taxrate[i]=(taxrate[i]-.05);
else if ((ms[i]=='h') && (grosspay[i]>500)) taxrate[i]=(taxrate[i]-.05);
else taxrate[i]=(taxrate[i]*1);
} //tax loop
for (i=0; i<counter; i++){
taxamount[i] = grosspay[i]*taxrate[i];}//end taxamount
for (i=0; i<counter; i++){
netpay[i]= grosspay[i]-taxamount[i];}//end netpay
cout<<endl;
for (i=0; i<counter; i++){
sumofnetpay+=netpay[i];} //end of sum of netpay
for (i=0; i<counter; i++){
averageofnetpay[i]= sumofnetpay/counter;}//end of average of netpay
for(int i = 0; i < MAX - 1; i++)
{
for(int j = i + 1; j < MAX; j++)
{
if(numbers[j] < numbers[i])
swap(numbers[i], numbers[j]);
}
}
void swap(int& x, int& y)
{
int temporary;
temporary = x;
x = y;
y = temporary;
}
cout
<<setw(10)<<"SSN"
<<setw(20)<<"First Name"
<<setw(20)<<"Last Name"
<<setw(10)<<"NET"
<<endl<<endl;
cout<<"---------------------------------------------------------------------------"<<endl;
for (i=0; i<counter; i++){
cout
<<setw(10)<<employeeid[i]
<<setw(20)<< firstname[i]
<<setw(20)<<lastname[i]
<<setw(10)<<netpay[i]
<<endl;}
system ("pause");
return 0;
}//end main
Last edited on Jan 25, 2011 at 5:40pm UTC
Jan 16, 2011 at 4:58am UTC
Edit the post to use a code block.
[code] //code goes here
[/code]
Jan 16, 2011 at 4:01pm UTC
will do
Last edited on Jan 16, 2011 at 5:52pm UTC
Jan 16, 2011 at 4:27pm UTC
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 115 116 117 118 119 120 121 122
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
const int MAX = 100;
main() {
char employeeid [100][12];
char firstname [100][10], lastname [100][15], ms[100];
int hoursworked [100];
double grosspay[100], netpay[100], numbers[100], table[100], hourlyrate[100], taxrate[100], taxamount[100],overtimepay[100], overtimehours[100],regularpay[100],averageofnetpay[100],sumofnetpay, numberofemployees[100] ;
int counter = 0;
int i, n;
ifstream fin("employee3.in" );
while (fin>>employeeid[counter]>>hoursworked[counter]>>hourlyrate[counter]>>ms[counter]>>firstname[counter]>>lastname[counter])
counter=counter+1;
for (i=0; i<counter; i++){
if (hoursworked[i] > 40) {
overtimehours[i] = hoursworked[i] - 40;
overtimepay[i] = overtimehours[i] * hourlyrate[i]*1.5;
regularpay[i]= hourlyrate[i] * 40; }
else {
overtimehours[i] = 0;
overtimepay[i] = 0;
regularpay[i] = hoursworked[i] * hourlyrate[i];}
}//for
for (i=0; i<counter; i++){
grosspay[i]=regularpay[i] + overtimepay[i];}// end grosspay loop
for (i=0; i<counter; i++){
if (grosspay[i]>1000)taxrate[i] = .3;
else if (grosspay[i]> 800) taxrate[i] = .2;
else if (grosspay[i]> 500) taxrate[i] = .1;
else taxrate[i] = 0;
if (ms[i]=='S' ) taxrate[i]=(taxrate[i]+.05);
else if (ms[i]=='s' ) taxrate[i]=(taxrate[i]+.05);
else if ((ms[i]=='H' ) && (grosspay[i]>500)) taxrate[i]=(taxrate[i]-.05);
else if ((ms[i]=='h' ) && (grosspay[i]>500)) taxrate[i]=(taxrate[i]-.05);
else taxrate[i]=(taxrate[i]*1);
} //tax loop
for (i=0; i<counter; i++){
taxamount[i] = grosspay[i]*taxrate[i];}//end taxamount
for (i=0; i<counter; i++){
netpay[i]= grosspay[i]-taxamount[i];}//end netpay
cout<<endl;
for (i=0; i<counter; i++){
sumofnetpay+=netpay[i];} //end of sum of netpay
for (i=0; i<counter; i++){
averageofnetpay[i]= sumofnetpay/counter;}//end of average of netpay
for (int i = 0; i < MAX - 1; i++)
{
for (int j = i + 1; j < MAX; j++)
{
if (numbers[j] < numbers[i])
swap(numbers[i], numbers[j]);
}
}
void swap(int & x, int & y)
{
int temporary;
temporary = x;
x = y;
y = temporary;
}
cout
<<setw(10)<<"SSN"
<<setw(20)<<"First Name"
<<setw(20)<<"Last Name"
<<setw(10)<<"NET"
<<endl<<endl;
cout<<"---------------------------------------------------------------------------" <<endl;
for (i=0; i<counter; i++){
cout
<<setw(10)<<employeeid[i]
<<setw(20)<< firstname[i]
<<setw(20)<<lastname[i]
<<setw(10)<<netpay[i]
<<endl;}
system ("pause" );
return 0;
}//end main
Last edited on Jan 25, 2011 at 5:40pm UTC
Jan 16, 2011 at 6:34pm UTC
123
Last edited on Jan 25, 2011 at 5:40pm UTC
Jan 16, 2011 at 7:41pm UTC
It's because no such object as "employeeid" exists at that level.
What does exist, however, is employee[X].employeeid[counter]
where X is a number from 0 to 99