| |
//This is a simple program that shows the user how to
//sort and use for loops
#include <iostream>
using namespace std;
void main()
{
int Weight[5];
int SortedWeight[3];
int HWeight;
int HWeightIndex;
int i, j;
cout<<"Enter 5 Weights in Pounds: \n";
for(i = 0; i < 5; i ++)
{
cout <<"Weight#" << i+1 <<": ";
cin >> Weight[i];
}
for(i = 0; i < 3; i ++)
{
HWeight = 0;
for(j = 0; j < 5; j ++)
{
if(Weight[j] > HWeight)
{
HWeight = Weight[j];
HWeightIndex = j;
}
}
SortedWeight[i] = HWeight;
Weight[HWeightIndex] = 0;
}
cout <<"Highest Weight: " << SortedWeight[0] << " lbs" << "\n";
cout <<"2nd Highest Weight: " << SortedWeight[1] << " lbs" << "\n";
cout <<"3rd Highest Weight: " << SortedWeight[2] << " lbs" << endl;
} |