Arrays in fuction not calculating division

So I have this code to calculate and display shareholders and their shares. It compiles fine and it all works except for the percentage of total shares function (computeSharePercentage) it just returns zeros as if its not doing the calculation at all and I can't figure out why, any help would be great!

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
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>  
#include <cmath>

using namespace std;

void getInputs(string* holders, int* shares);
void computeTotalShares(int* shares, int& totalshares);
void computeSharePercentage(int* shares, int& totalshares, double* percentage);
void getLargestShare(int* shares, double& high);
void outputResults(string* holders, int* shares, int& totalshares, double* percentage, double& high);


int main()
{
	string holders[5];
	int shares[5];
	int totalshares=0;
	double percentage[5];
	double high;
	
	getInputs(holders, shares);
	computeTotalShares(shares, totalshares);
	computeSharePercentage(shares, totalshares, percentage);
	getLargestShare(shares, high);
	outputResults(holders, shares, totalshares, percentage, high);
	
}

void getInputs(string* holders, int* shares)
{
	int i;
	for(i=0;i<5;i++)
	{
		if(i==0)
		{
			cout << "Enter the first Shareholder's name: \n";
		}
		else
		{
			cout << "Enter another Shareholder's name: \n";
		}
		
		cin >> holders[i];
		
		cout << "How many shares do they own?\n";
		
		cin >> shares[i];
		
	}
}

void computeTotalShares(int* shares, int& totalshares)
{
	int t;
	for(t=0;t<5;t++)
	{
		totalshares = totalshares + shares[t];
		
	}
}

void computeSharePercentage(int* shares, int& totalshares, double* percentage)
{
	int p;
	for(p=0;p<5;p++)
	{
		percentage[p] = (shares[p]/totalshares)*100;
	}
}

void getLargestShare(int* shares, double& high)
{
	int l;
	for(l=0;l<5;l++){
	if (shares[l] > high)
			{
			high = shares[l];
			}
	}
}

void outputResults(string* holders, int* shares, int& totalshares, double* percentage, double& high)
{
	int o, h, f;
	
	cout << "Shareholder      Share Amount      % of Total Shares\n";
	
	cout << fixed << setprecision(2) << endl;
	
	for(o=0;o<5;o++)
	{
		
		cout << left << setw(15) << holders[o]
			<< left << setw(20) << shares[o] 
			<< percentage[o] << endl;
		
	}

	cout << fixed << setprecision(0);
	
	cout << "Total          " << totalshares << endl;
		
	
	for(h=0;h<5;h++){
		if (shares[h] > high)
		{
			high = shares[h];
		}
	}
	
	for(f=0;f<5;f++){
		if (high == shares[f])
		{
			cout << "The Highest Shareholder is " << holders[f];
        }
	}
}	
That's because shares[p] and total shares are both integers. Dividing a smaller integer by a larger integer gives 0. You need to cast one of them into a double.
Thanks!
Topic archived. No new replies allowed.