math problem

I want to make a program and have it explain to C++ that my int x is smaller than '<' my int z.

Something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
    int x, z;

    x == < z;

    if(x < z)
    
        cout << "X is smaller than Z!";
    
    else

        cout << "Z is smaller than X!";

return 0;
}


This won't work, I know. But how do I explain to C++ without using fixed numbers? My variables should not have values, only rules.
Last edited on
C++ is not that kind of programming language.
Thats sad. It's the only language i "know"...
You might be looking for a declarative programming language; http://en.wikipedia.org/wiki/Declarative_programming
You could create a class containing two elements;
int less, int more.

in the set method, you check if the value follows the rules, if it does, set. If the input does not follow the rules: Don't set, or set to the edge (make less = more - 1, for example)

1
2
3
4
5
6
7
8
9
class smth
{
public:
    smth() : less(0), more(1) {}
    void setMore(int a){if (a > less) more = a; else more = less + 1;}
    void setLess(int a){if (a < more) less = a; else less = more - 1;}
private:
    int less, more;
};
Topic archived. No new replies allowed.