fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. struct Names
  7. {
  8. string F_name; //Creating structure called Names.
  9. string L_name;
  10. char Mi;
  11. };
  12. struct Payrate
  13. {
  14. double rate;
  15. double hoursworked; //Creating structure called Payrate.
  16. double gross;
  17. double net;
  18. };
  19. int main()
  20. {
  21.  
  22. double stateTax = 0, federalTax = 0, unionFees = 0, timeHalf = 1.5; //Initializing variables.
  23. const int size = 2; //Array size.
  24. Payrate employee[3]; //Structure variables
  25. Names Listofnames[3];
  26. cout << "size = "<<sizeof(Listofnames)/sizeof(Listofnames[0]) <<endl;
  27. for (int counter = 0; counter < 3; counter++) //Initializing for loop.
  28. {
  29. cout << "What's your first name?: " << endl;
  30. cin >> Listofnames[counter].F_name;
  31. cout << "What's your last name?: " << endl; //Displaying names, and hours worked, rate.
  32. cin >> Listofnames[counter].L_name;
  33. cout << "What is your middle initial?: " << endl;
  34. cin >> Listofnames[counter].Mi;
  35. cout << "How many hours did you work? Please enter a number between 1-50: " << endl;
  36. cin >> employee[counter].hoursworked;
  37. cout << "What is your hourly rate? Please enter a number between 1-50: " << endl;
  38. cin >> employee[counter].rate;
  39.  
  40. if (employee[counter].hoursworked < 0 || employee[counter].hoursworked >50) //Initializing conditional statements.
  41. {
  42. cout << "Sorry you entered a erong entry. Pc shutting off " << endl; //Displays what happens is user inputs a number under 0 or over 50.
  43. }
  44. if (employee[counter].rate < 0 || employee[counter].rate > 50) //Initializing conditional statements.
  45. {
  46. cout << "Sorry you entered a erong entry. Pc shutting off " << endl; //Displays what happens is user inputs a number under 0 or over 50.
  47. }
  48. if (employee[counter].hoursworked <= 40) //Initializing conditional statements.
  49. {
  50. employee[counter].gross = employee[counter].hoursworked * employee[counter].rate; //Calculating gross.
  51. }
  52. else if (employee[counter].hoursworked > 40) //Initializing conditional statements.
  53. {
  54. employee[counter].gross = employee[counter].hoursworked * (employee[counter].rate * timeHalf); //Calculating gross.
  55. }
  56. stateTax = employee[counter].gross * 0.06;
  57. federalTax = employee[counter].gross * 0.12; //Calculates all the tax fees, and net.
  58. unionFees = employee[counter].gross * 0.02;
  59. employee[counter].net = employee[counter].gross - (stateTax + federalTax + unionFees);
  60. }
  61. cout << "FirstN " << "MI " << "LastName " << "\t" << "Rate " << "HoursWorked " << "TimeHalf " << "StateTax " << "FederalTax " << "UnionFees " << "Gross " << " " << "Net " << endl; //Displays header of output.
  62. cout << "==================================================================================================================" << endl;
  63. for (int counter = 0; counter < sizeof(Listofnames)/sizeof(Listofnames[0]); counter++)
  64. {
  65. //Output.
  66. cout << Listofnames[counter].F_name << "\t" << fixed << setprecision(2) << Listofnames[counter].Mi << " " << Listofnames[counter].L_name << "\t" << employee[counter].rate << "\t" << employee[counter].hoursworked << "\t" << setw(7) << timeHalf << "\t" << setw(8) << stateTax << setw(12) << federalTax << "\t" << unionFees << "\t" << employee[counter].gross << "\t" << employee[counter].net << endl;
  67. system("pause");
  68. }
  69.  
  70. cout << "size = "<<sizeof(Listofnames)/sizeof(Listofnames[0]) <<endl;
  71. }
Success #stdin #stdout #stderr 0s 16072KB
stdin
ayush
dobhal
D
10
3
ayush1
dobhal
D
10
31
ayush2
dobhal
D
10
30
stdout
size = 3
What's your first name?: 
What's your last name?: 
What is your middle initial?: 
How many hours did you work? Please enter a number between 1-50: 
What is your hourly rate? Please enter a number between 1-50: 
What's your first name?: 
What's your last name?: 
What is your middle initial?: 
How many hours did you work? Please enter a number between 1-50: 
What is your hourly rate? Please enter a number between 1-50: 
What's your first name?: 
What's your last name?: 
What is your middle initial?: 
How many hours did you work? Please enter a number between 1-50: 
What is your hourly rate? Please enter a number between 1-50: 
FirstN MI LastName 	Rate HoursWorked TimeHalf StateTax FederalTax UnionFees Gross   Net 
==================================================================================================================
ayush	D dobhal	3.00	10.00	   1.50	   18.00       36.00	6.00	30.00	24.00
ayush1	D dobhal	31.00	10.00	   1.50	   18.00       36.00	6.00	310.00	248.00
ayush2	D dobhal	30.00	10.00	   1.50	   18.00       36.00	6.00	300.00	240.00
size = 3
stderr
sh: 1: pause: not found
sh: 1: pause: not found
sh: 1: pause: not found