Repetitions

////
Last edited on
For example, the first number, 178, comes out as 871.

No, it doesn't. You're processing digits from right to left and outputting them as they are processed. Why you think outputting digits as you process them is a good idea is anyone's guess. If you want to output the number, output the number. Strike line 28 and add cout << num; directly after line 17.

For the love of god, please use better variable names and pay attention to the warnings generated by your compiler.
Since our OP was rude enough to delete the content of his first post here's the basic content:

Q: "Why are the numbers in my file being reflected (178 is output as 871)?"

File content:
8
178
536
6392
2388
6767
8631
16789
25579

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

using namespace std;

int main()
{

    ifstream infile("numbers.txt");

    int num, curDigit, prevDigit;
    infile >> prevDigit;

    for (int i = 0; i<prevDigit; i++)
    {
        infile >> num;
        int j = 0, curDigit, a, flag = 1;

        while (num != 0)
        {
            curDigit = num % 10;
            num /= 10;
            if (j++ == 0) { a = curDigit; }
            else if (a < curDigit) { flag = 0; }
            else a = curDigit;
            curDigit<prevDigit;
            cout << curDigit;
        }

        if (flag == 1)cout << " Well-ordered" << endl;
        else cout << " Non well-ordered" << endl;
    }

    system("PAUSE");
    return 0;
}

Topic archived. No new replies allowed.