LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Lost in mathematics (https://www.linuxquestions.org/questions/programming-9/lost-in-mathematics-830293/)

jmc1987 09-04-2010 04:58 AM

Lost in mathematics
 
Okay I have a possible really stupid question to ask and it really confused me by the way I think I was taught in school. I am refering to the < and > signs.

5<10. The way I think I was taught that it would read 5 is greater than 10 because 5 would have the big mouth eating the 10. But the way I seem to be wrong that it means 5 is less then 10.

5>10. I normally would read this as 5 is less then 10 because the mouth is eating the 5 which I would consider true. What I read would be that is false and it really reads 5 is greater then 10.

I just realized all my expression I am righting are comming out backwards. So has anybody ever known that in school the way I was taught or so I thought?

and just to be clear
5<10 would be 5 is less then 10 which is true
and
5>10 would be 5 is greater then 10 which is false.

correct?

I just don't want to right a million expressions and have to rewrite it all.

Just a note to all you younger generations or just people still in school. You might want to not sleep in class ;).

Just to add.
I wrote this to test it and it comes out like 45<10 45 is less then 10 true.
Code:

#include <iostream>

using namespace std;
int main()
{
    int myAge, yourAge;
    myAge = 45;
    yourAge = 50;

    if (myAge < yourAge){
        cout << "Iam am younger.\n";
    }
        else {
            cout << " I am older.\n.";
        }


    return 0;
}


rcbrgs 09-04-2010 05:21 AM

Hi jmc!

The way I was taught is that the symbol "<" means "is less than", and to interpret correctly any use of it, you just have to substitute the expression for the symbol.

So "X < Y" should be read as "X is less than Y".

The same goes for equivalent symbols (>, >=, <=).

Your code correctly outputs "Iam am younger." because myAge < yourAge, that is, 45 < 50, that is, 45 "is less than" 50.

I have heard about the "eating" interpretation, I believe you can use this way of interpreting the symbols, as long as you always consider that the "mouth" of the symbol is "greedy" and tries to eat the bigger number. If this is true, the sentence is true.

I believe that more important than to use a "current generation" interpretation, you should tweak yours so that is both correct and easily remembered.

Cheers!
Renato.

jmc1987 09-04-2010 05:51 AM

Yea I may have been taught like that. It has just been years since I've been in school but I got it down now. I decided to rewrite my script to be a little less boring though

Code:

// Age Test script

#include <iostream>
//defining std for the whole progrom
using namespace std;
int main()
{
    int myAge, yourAge; // Yours and My age

    cout << "My age: "; cin >> myAge ; cout << endl;  //Ask for myAge and allows you to enter a number
    cout << "Your age: "; cin >> yourAge ; cout << endl; //ask for yourAge and allows you to enter a number

    // Test ages from from less equal or greater
    if (myAge == yourAge){
        cout << "I am equally as old.\n"; //if our ages are equal run this
    }
        else if (myAge > yourAge){
            cout << "I am older.\n.";  // if myAge is greater than yourAge print this
        }
            else {

                cout << "I am younger"; // if myAge is less than yourAge print this
            }


    return 0;
}

I get to type in my numbers now ;)!

By the way does anybody know how easy it would be to rewrite a c program into c++? I assume its like a total overhaul.

Sergei Steshenko 09-04-2010 06:13 AM

Quote:

Originally Posted by jmc1987 (Post 4087778)
...
By the way does anybody know how easy it would be to rewrite a c program into c++? I assume its like a total overhaul.

Correctly written "C" program should work as a C++ one too - C99 is an almost strict subset of C++.

igadoter 09-04-2010 06:46 AM

@Sergei Steshenko
I disagree. Crodile and birds according the evolution theory have the same parents. Modern C and C++ also have the same parent. But they are completely different despite some formal similarities. Learning C++ as a some kind of extension of C is a waste of time. In my opinion forget everything you learned about C if you want to learn C++.

MTK358 09-04-2010 06:58 AM

Think of it this way -- the wider side of the symbol points to the bigger number, and the thin, pointy side points to the smaller number.

Sergei Steshenko 09-04-2010 02:04 PM

Quote:

Originally Posted by igadoter (Post 4087800)
@Sergei Steshenko
I disagree. Crodile and birds according the evolution theory have the same parents. Modern C and C++ also have the same parent. But they are completely different despite some formal similarities. Learning C++ as a some kind of extension of C is a waste of time. In my opinion forget everything you learned about C if you want to learn C++.

You apparently disagree with some statements I haven't made.

The statement I made is essentially this:

http://www.parashift.com/c++-faq-lit...c-and-cpp.html :

Quote:

[32.1] What do I need to know when mixing C and C++ code?
...
BTW there is another way to handle this whole thing: compile all your code (even your C-style code) using a C++ compiler. That pretty much eliminates the need to mix C and C++, plus it will cause you to be more careful (and possibly —hopefully!— discover some bugs) in your C-style code.
And if we are already talking about "C" vs C++, then I disagree with you - one absolutely needs to know "C", and better yet in addition to it at least one assembly - it's very sad/frustrating to deal with code of those who have no idea what is actually happening at low(er) level.

wroom 09-04-2010 05:49 PM

Quote:

Originally Posted by Sergei Steshenko (Post 4088087)
...And if we are already talking about "C" vs C++, then I disagree with you - one absolutely needs to know "C", and better yet in addition to it at least one assembly - it's very sad/frustrating to deal with code of those who have no idea what is actually happening at low(er) level.

I have to say i totally agree with you, Sergei.

Working as a consultant i very often hear employer executives complain about that so many programmers seem to live in the clouds with their OO coding style, not knowing much of how their code actually executes in the system, and therefore bringing issues into the system which may sometimes be extremely difficult to remedy.


All times are GMT -5. The time now is 06:54 PM.