output numbers in ascending order?

How can I get input numbers to correctly arrange themselves in ascending order no matter what? example. 1, 2, 3, 4, 5, 6 in my output


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
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main()
{
	ifstream fin1, fin2;
	ofstream fout;

	fin1.open("numbers1.txt");
	if(fin1.fail())
	{
		cout << "Input file opening failed." << endl;
		exit(1);
	}

	fin2.open("numbers2.txt");
	if(fin2.fail())
	{
		cout << "Input file opening failed." << endl;
		exit(1);
	}

	fout.open("output.txt");
	if(fout.fail())
	{
		cout << "Output file opening failed." << endl;
		exit(1);
	}

	int number1, number2;

	fin1 >> number1;
	fin2 >> number2;

	do
	{
		if(number1 == number2)
		{
			fin1 >> number1;
			fin2 >> number2;
			fout << number1 << endl;
			fout << number2 << endl;
			
		}
		if(number1 > number2)
		{
			fin2 >> number2;
			fout << number2 << endl;
			
		}
		if(number2 > number1)
		{
			fin1 >> number1;
			fout << number1 << endl;
		}
	}while(!fin1.eof() && !fin2.eof());
	
	while(!fin2.eof())
	{
		fin2 >> number2;
		fout << number2 << endl;
		
	}
	
	
	while(!fin1.eof())
	{
		fin1 >> number1;
		fout << number1 << endl;
		
	}
	
	if(fin1.eof())
	{
		if(number2 > number1)
		{
			fout << number1 << endl;
		}
		if(number1 > number2)
		{
			fout << number1 << endl;
		}
		if(number1 == number2)
		{
			fout << number1 << endl;
		}
	}
	
	if(fin2.eof())
	{
		if(number2 > number1)
		{
			fout << number2 << endl;
		}
		if(number1 > number2)
		{
			fout << number2 << endl;
		}
		if(number1 == number2)
		{
			
			fout << number2 << endl;
		}
	}
	
	
		
	fin1.close();
	fin2.close();
	fout.close();
	
	return 0;
}
Posting a question in all the forums will not help. Neither will posting the same question in different ways.
People here visit all the forums and check all the posts and try to answer them if they can.

So, be patient and your issues will be solved. :-)
You want to output all numbers from two foies in ascending order?
Like file1: 1, 3, 2; file2: 6, 5, 4; output: 1, 2, 3, 4, 5, 6?

If so, you need to load numbers from both files into array, sort them and then output to file.
Topic archived. No new replies allowed.