(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();
}

Recommended Answers

All 4 Replies

If I understand your problem correctly, all you need to do is allocate variables to hold the sum of normal hours worked and OT hours worked, set them to 0.
As you do the pay calculations, add the hours to their corresponding sums.

ok it seems like you know what your talking bout thankfully, so would i be correct in thinking i can add up 'hoursworked' and all i need to do is store the calculation in a variable, if so the probelm i am coming across is how to total the array to store it in a variable
Thanks

I Will Be Grateful For Any Information That May Help Thanks For Those Who Take An Interest

It's Starting To Sound A Bit Like A Nigerian 419 Scam.
(well that's atleast the way the write for some reason)

Maybe We Will Get 15 Million US Dollars If We Help?

You don't "total the array", you add each element's value to a variable, in this case doing so as you do other processing with the elements.

int data[5] = { 3, 5, 1, 6, 7 };
int i;
int sum = 0;

for( i = 0; i < 5; i++ )
{
    cout << data[i] << endl; //or whatever processing you need
    sum += data[i];
}

cout << "Sum of the array elements is: " << sum << endl;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.