LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-04-2010, 04:58 AM   #1
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 866

Rep: Reputation: 110Reputation: 110
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;
}

Last edited by jmc1987; 09-04-2010 at 05:03 AM. Reason: just added me test script
 
Old 09-04-2010, 05:21 AM   #2
rcbrgs
Member
 
Registered: Aug 2010
Posts: 30

Rep: Reputation: 14
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.
 
Old 09-04-2010, 05:51 AM   #3
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7
Posts: 866

Original Poster
Rep: Reputation: 110Reputation: 110
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.
 
Old 09-04-2010, 06:13 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by jmc1987 View Post
...
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++.
 
Old 09-04-2010, 06:46 AM   #5
igadoter
Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: slack 12.2, debian-Trinity , openbsd
Posts: 729

Rep: Reputation: 56
@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++.
 
Old 09-04-2010, 06:58 AM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
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.
 
Old 09-04-2010, 02:04 PM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by igadoter View Post
@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.
 
Old 09-04-2010, 05:49 PM   #8
wroom
Member
 
Registered: Dec 2009
Location: Sweden
Posts: 83

Rep: Reputation: 24
Quote:
Originally Posted by Sergei Steshenko View Post
...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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How much/what branches of/mathematics do you know? joeBuffer General 33 08-22-2009 09:47 PM
Where can I get mathematics........? schneemann Suse/Novell 1 01-08-2006 04:28 PM
mathematics ? Volcano Programming 6 10-05-2005 11:17 PM
bash mathematics possible? stabu Linux - Newbie 5 04-30-2004 04:45 AM


All times are GMT -5. The time now is 04:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration