Help a new guy out!

Write your question here.

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

using namespace 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;
	else if (b > a && b > c)
		cout << "While sorting by weights, more people can get on the elevator with a total of " << b << " people." << endl;
	else if (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?
Hello cweiss1,

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.

Hope that helps,

Andy
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.

Topic archived. No new replies allowed.