problem finding the largest number in a vector

I am self teaching myself c++ as a result of that i dont have any peers to help me with any problems that i might come across. I have tried to solve this problem in many different ways spending about an hour or more on it. This is a drill section of the book but please note that i am not asking for you to do my so called homework i just need help with this one bit of the problem. I will post my whole code as i think that the problem may not just be in the most obvious spot.

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
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
inline void keep_window_open() { char ch; cin >> ch; }

//made two vectors figuring it would be easier 
//tried with one vector but didn't succeed
int main() {
	cout << "Please enter two numbers followed by | and enter.\n";
	double var1;
	double var2;
	int number = 0;
	vector <double> variables;
	vector <double> greater;
	while (cin >> var1 && cin >> var2){
		cout << "The numbers you entered were " << var1 << " & " << var2 << "\n";
		if (var1 < var2){
			cout << var1 << " is smaller than " << var2 << " and " << var2 << " is larger than " << var1 << ".\n";
			//after multiple tries thought push_back would work best here in the if statements
			greater.push_back(var2);
			variables.push_back(var1);
			if ((var1 - var2) <= (1.0 / 10000000) || (var2 - var1) >= (1.0 / 10000000)){
				cout << "The numbers are almost equal.\n";
			}
		}
		else if (var2 < var1) {
			cout << var2 << " is smaller than " << var1 << " and " << var1 << " is larger than " << var2 << ".\n";
			greater.push_back(var1);
			variables.push_back(var2);
			if ((var1 - var2) <= (1.0 / 10000000) || (var2 - var1) >= (1.0 / 10000000)){
				cout << "The numbers are almost equal.\n";
			}
		}
		else  {
			cout << "The numbers are equal.\n";
			greater.push_back(var1);
			variables.push_back(var1);
		}
		
		sort(variables.begin(), variables.end());
		cout << "The numbers you have listed so far are\n";
		cout << variables[0] << " Is the smallest number entered so far.\n";
		for(int i = 0; i >= 1; ++i){
			//possibly where the problem is?
			cout << greater[i + 0] << " is the largest number entered so far.\n";
		}
	}
}
The for loop on line 46 will never execute as the condition i >= 1 can never be true with i initially set to 0.

//made two vectors figuring it would be easier
//tried with one vector but didn't succeed

What made you think that?

One vector is all that is required if you want to keep track of every value entered. If you don't want to keep track of every value entered, you don't even need that much.
I was trying to think of different ways and I came up with that originally i did have the for loop i <= 1 and at one point I had it at i < greater.size() but i came across an infinite loop.
Topic archived. No new replies allowed.