Console read out issue

The program is not displaying my cout statements un the second half of my program. What doesn't it work and how can I fix it? This issue starts at line 59.

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

int main()
{
    // User prompt and three values.
    double x, y, z;     // x, y, and z are the values inputted by the user.
    cout << "Please enter three different values, then press enter.\n";
    cin >> x >> y >> z;
    cout << "\n";

    // Determining user's value input
    if (x == y && y == z)
    {
        cout << "Error. Please restart the program and enter 3 distinct values.\n";
    }
    else
    {
        // Value order menu

        char order;
        cout << "Press A for ascending order or D for descending order, then press enter.\n";
        cin >> order;
        cout <<"\n";

        if (order == 'A')
        {
            cout << "Now ranking in ascending order...\n";

            if (x < y && y < z)
            {
                cout << x << ", " << y << ", " << z << ".\n";
            }
            else if (x < z && z < y)
            {
                cout << x << ", " << z << ", " << y << ".\n";
            }
            else if (y < x && x < z)
            {
                cout << y << ", " << x << ", " << z << ".\n";
            }
            else if (y < z && z < x)
            {
                cout << y << ", " << z << ", " << x << ".\n";
            }
            else if (z < y && y < x)
            {
                cout << z << ", " << y << ", " << x << ".\n";
            }
            else if (z < x && x < y)
            {
                cout << z << ", " << x << ", " << y << ".\n";
            }
        }

        else if (order == 'D')
        {
            cout << "Now ranking in descending order...\n";
            // WHY IS IT NOT WORKING??

            if (x > y && y > z)
            {
                cout << x << ", " << y << ", " << z << ".\n";
            }
            else if (x > z && z > y)
            {
                cout << x << ", " << z << ", " << y << ".\n";
            }
            else if (y > x && x > z)
            {
                cout << y << ", " << x << ", " << z << ".\n";
            }
            else if (y > z && z > x)
            {
                cout << y << ", " << z << ", " << x << ".\n";
            }
            else if (z > y && y > x)
            {
                cout << z << ", " << y << ", " << x << ".\n";
            }
            else if (z > x && x > y)
            {
                cout << z << ", " << x << ", " << y << ".\n";
            }
        }
        else
        {
            cout << "Error. Please enter either A or D  to make your choice.";
        }
    }
    return 0;
}
Last edited on
I fixed it by replacing the greater-than operators with greater-than-equal operators.
Hello PacificAtlantic,

That is not your only problem.

1
2
cout << "Please enter three different values, then press enter.\n";
cin >> x >> y >> z;

So I could enter 102030 for three different values an it would be OK?

If you "cin" is for 3 different variables then the prompt should include "separated by a space" or give an example like "(1 2 3)". Or the first user will break your program without trying.

Then there is:
1
2
3
4
5
cout << "Press A for ascending order or D for descending order, then press enter.\n";
cin >> order;
cout <<"\n";

if (order == 'A')


What happens when your great user enters "a" or "d"?
You could fix this with if (std::toupper(order) == 'A') or if (order == 'A' || order == 'a'). "std::toupper()" requires header file "cctype".

Changing the (>) to (>+) is not going to solve getting to line 58 if "order" is euaal to "d".

Andy

just check whether the crusor is moving after your input or not, texts may coincide with background due to some issue. try reinstalling your compiler, its works perfect in my compiler
Topic archived. No new replies allowed.