(Using MS Visual Basic 2008)
Hi I have Created this program so far for a uni assignement, how ever i need to be able to total the arrays so i can display correct total overall, however the array size has to be defined by the user therefore the size of the array wont be known, so basically the array found in the code for hoursworked (hoursworked) i need a total for based on the users information.
I Will Be Grateful For Any Information That May Help Thanks For Those Who Take An Interest
Here Is The Code:
#include"stdafx.h"
#include <iostream>
#include <typeinfo>
#include <typeinfo>
using namespace std;
int main()
{
int employees;
float minwage=20, wages=0.0, overtime=0.0, overtimepayrate=0.0, overtimewages=0.0, totalwages=0.0;
cout << "Please Enter The Amount Of Employees You Want To Process: ";//User determines how many employees to process
cin >> employees;//stores the amount entered by user
float *hoursworked = new float[employees];
float *payrate = new float[employees];
for (int i = 0; i < employees; i++)
{
cout<<"\nPlease Enter How Many Hours The Employee "<<(i+1)<<" Has Worked: ";//Ask the user how many hours each employee entered has worked
cin >> hoursworked[i];//stores the amount of hoursworked entered by the user
cout << "Please Enter The Payrate Of Employee " << (i+1) << ": ";//Ask the user the payrate of each employee
cin >> payrate[i];//Stores the payrate of each employee
while ( hoursworked[i] < 0 )//keep looping until a valid employee amount is entered
{
cout << "Invalid Amount Of Hours Worked, Please Try Again.\n";//Displays an error message for user
cin >> hoursworked[i];//stores the amount of hoursworked entered by the user
}
}
cout << "\n\n";
for (int i = 0; i < employees; i++)
{
if(hoursworked[i]==0)//If criteria is equal to 0, the internal code will execute
{
cout << "Wages for employee " << (i+1) << ": " << minwage;
cout << "\n\n";
}
else if(hoursworked[i]<=35)//If criteria is less than or equal to 35, the internal code will execute
{
wages=(hoursworked[i]*payrate[i]);
cout << "Wages for employee " << (i+1) << ": " << wages;
cout << "\n\n";
}
else if(hoursworked[i]>35 && hoursworked[i]<50)//If criteria is greater than 35 the internal code will execute
{
wages=(payrate[i]*35);
overtime=(hoursworked[i]-35);
overtimepayrate=(payrate[i]*1.5);
overtimewages=(overtimepayrate*overtime);
totalwages=(wages+overtimewages);
cout << "Wages for employee " << (i+1) << ": " << totalwages;
cout <<"\n\n";
}
else if(hoursworked[i]>=50)
{
hoursworked[i]=50;
wages=(payrate[i]*35);
overtime=15;
overtimepayrate=(payrate[i]*1.5);
overtimewages=(overtimepayrate*overtime);
totalwages=(wages+overtimewages);
cout << "Wages for employee " << (i+1) << ": " << totalwages;
cout << "\n\n";
}
}
cout<<"Total normal hours"<<"\t"<<"Total overtime hours"<<"\t"<<"Total wages";
cout<<"\n\n";
//I'm assuming arrays totals should be here.
cout<<" (T.N.H Here)"<<"\t"<<" (T.O.H Here)"<<"\t"<<" (T.W Here)";
delete[] hoursworked, payrate;
cin.ignore(); cin.ignore();
}