#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace std;
string names [12];
int weights [12];
void readInNames (int size)
{
ifstream fin ("namesProject4.txt");
for (int i =0; i < size; i++)
{
fin >> names [i];
}
}
void readInWeights (int size)
{
ifstream fin ("weightsProject4.txt");
for (int i =0; i < size; i++)
{
fin >> weights [i];
}
}
void print (int size)
{
for (int i=0; i<size; i++)
{
cout << names[i] << "\t" << weights[i] << endl;
}
}
int howmany ()
{
int total = 0, i = 0;
while (total < 1100)
{
total += weights [i];
i++;
}
i--;
return i;
}
void descendingOrder (int size)
{
int z;
string x;
for(int i=0; i< size; i++)
{
for(int j=i+1; j < size; j++)
{
if(weights[i] < weights[j])
{
z = weights[j];
weights[j] = weights[i];
weights[i] = z;
x = names[j];
names[j] = names[i];
names[i] = x;
}
}
}
}
void ascendingNames (int size)
{
for ( int i = 0; i < size ; ++i)
{
string key = names[i];
int key1 = weights[i];
int position = i;
while (position > 0 && names[position-1] > key)
{
names[position] = names[position-1];
weights[position] = weights[position-1];
position--;
}
names[position] = key;
weights [position] = key1;
}
}
int main ()
{
int a, b, c, size = 12;
readInNames(size);
readInWeights(size);
cout << "List of People" << endl;
print (size);
cout << endl;
cout << "People that can get on the elevator without sorting." << endl;
a = howmany();
print (a);
cout << endl;
cout << "List of people while being sorted by their weight." << endl;
descendingOrder (size);
print (size);
cout << endl;
cout << "People that can get on the elevator that are sorted by weight." << endl;
b = howmany();
print (b);
cout << endl;
cout << "List of people while being sorted by their name." << endl;
ascendingNames (size);
print (size);
cout<< endl;
cout << "People that can get on the elevator that are sorted by their names." << endl;
c = howmany();
print (c);
cout << endl;
if (a > b && a > c)
cout << "Without sorting, more people can get on the elevator with a total of " << a << " people." << endl;
elseif (b > a && b > c)
cout << "While sorting by weights, more people can get on the elevator with a total of " << b << " people." << endl;
elseif (c > a && c > b)
cout << "While sorting alphabetically, more people can get on the elevator with a total of " << c << " people." << endl;
cout << endl;
cout << "This was programmed by Christopher Weiss" << endl;
Hey guys i cant see to get this code to show up on my output screen any help?
i cant see to get this code to show up on my output screen
Exactly what do you mean, the entire source code or just the "cout"statements?
The entire source code will not output to the screen when the program runs just the parts that start with"cout".
Be more specific about what is or is not showing up on the screen. Also state what you expect to see.
Line 130. Not everyone is willing to put their name. It is your choice. Also after line 130 you are missing a "return 0;" and the closing brace of main.
A common issue is that on windows the program executes so fast the output window opens and closes too fast to see it, which can be cured with a dummy cin statement (read something you don't actually need) or the dubious system("pause") line.