Need help with problem in my source code

Heres the code

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include<iostream>
#include<cmath>
#include<string>
#include<istream>
#include<iomanip>

using namespace std;

struct Cargo
{
	string label;
	double weight;
	int height, width, length;
	int cargo[100];
	void initCargo(Cargo cargo[], int height, int width, int length,
	double weight, string label)
	{
		
	}
	double cargoWeight(Cargo cargo)
	{
	
	}
	int cargoVolume(Cargo cargo)
	{

	}
	void printCargo(Cargo cargo)
	{
		
	}
};
void loadPlane(Cargo allCargo[],int size, double maxWeight, double &usedWeight, int
maxVolume, int &usedVolume );
void printWeight( double maxWeight, double &usedWeight);
void printVolume( int maxVolume, int &usedVolume);
void printHeaviest(Cargo allCargo[]);
void printLargest(Cargo allCargo[]);
void printCargo(Cargo allCargo[],int size);

void main()
{
	Cargo allCargo[100];
	double maxWeight=50000;
	double usedWeight=0;
	int maxVolume=3000000;
	int usedVolume=0;
	int size;
	for(int i=0;i<100;i++)
	{
	cout<<"Input label: ";
	cin>>allCargo[i].label;
	if(allCargo[i].label=="quit")
		break;
	cout<<"Input weight: ";
	cin>>allCargo[i].weight;
	cout<<"Input height: ";
	cin>>allCargo[i].height;
	cout<<"Input width: ";
	cin>>allCargo[i].width;
	cout<<"Input length: ";
	cin>>allCargo[i].length;
	cout<<endl;
	size=i+1;
	

	}
	cout<<endl;
	loadPlane(allCargo,size,maxWeight,usedWeight,maxVolume,usedVolume);
	printWeight(maxWeight,usedWeight);
	printVolume(maxVolume,usedVolume);
	printHeaviest(allCargo);
	printLargest(allCargo);
	printCargo(allCargo,size);
	
	
	
}

void loadPlane(Cargo allCargo[],int size, double maxWeight, double &usedWeight, int
maxVolume, int &usedVolume)
{
	for(int i=0;i<size;i++)
	{
		allCargo[i].weight;
		usedWeight=usedWeight+allCargo[i].weight;
	}
	for(int s=0;s<size;s++)
	{
		usedVolume=(allCargo[s].height*allCargo[s].width*allCargo[s].length)+usedVolume;
	}
}
void printWeight( double maxWeight, double &usedWeight)
{
	double unusedWeight;
	cout<<"--- Cargo Statistics ---"<<endl;
	cout<<fixed<<setprecision(2);
	cout<<"Maximum Cargo Weight: "<<maxWeight<<" pounds"<<endl;
	unusedWeight=maxWeight-usedWeight;
	cout<<"Unused Cargo Weight: "<<unusedWeight<<" pounds"<<endl<<endl;
}
void printVolume( int maxVolume, int &usedVolume)
{
	int unusedVolume;
	cout<<"Maximum Cargo Volume: "<<maxVolume<<" cubic inches"<<endl;
	unusedVolume=maxVolume-usedVolume;
	cout<<"Unused Cargo Volume: "<<unusedVolume<<" cubic inches"<<endl<<endl;
}
void printHeaviest(Cargo allCargo[])
{
	double heaviest=allCargo[0].weight;
	double temp=0;
	for(int i=0;i<100;i++)
	{
		if(allCargo[i].weight>temp)
			temp=allCargo[i].weight;
	}
	cout<<fixed<<setprecision(2);
	cout<<"Heaviest container weighed: "<<temp<<" pounds"<<endl;
}
void printLargest(Cargo allCargo[])//PROBLEM IS IN THIS FUNCTION
{
	int temp=0;
	int store[100];
	for(int i=0;i<100;i++)
	{
		store[i]=allCargo[i].height*allCargo[i].width*allCargo[i].length;
	}
	for(int s=0;s<100;s++)
	{
		if(store[s]>temp)
			temp=store[s];
	}
	cout<<"Largest container had volume of: "<<temp<<" cubic inches"<<endl<<endl;

}
void printCargo(Cargo allCargo[], int size)
{
	cout<<"--- Table of Cargo Containers ---"<<endl;
	cout<<"Dimensions        Volume         Weight        Label"<<endl;
	for(int i=0;i<size;i++)
	{
		cout<<allCargo[i].length<<" x "<<allCargo[i].width<<" x "<<allCargo[i].height<<"           ";
		cout<<allCargo[i].height*allCargo[i].width*allCargo[i].length<<"            ";
		cout<<allCargo[i].weight<<"           ";
		cout<<allCargo[i].label<<endl;
	}
} 


when i compile it, the largest container volume is always a very big number, can anyone please help because i am stuck. The function is soposed to loop through the volume of each container and cout the largest one.
Last edited on
Topic archived. No new replies allowed.