LinuxAnswers - the LQ Linux tutorial section.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org [SOLVED] Lost in mathematics
 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

 09-04-2010, 05:58 AM #1 jmc1987 Member   Registered: Sep 2009 Location: Oklahoma Distribution: Debian, CentOS, windows 7 Posts: 866 Rep: 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 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 06:03 AM. Reason: just added me test script
 09-04-2010, 06:21 AM #2 rcbrgs Member   Registered: Aug 2010 Posts: 30 Rep: 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.
 09-04-2010, 06:51 AM #3 jmc1987 Member   Registered: Sep 2009 Location: Oklahoma Distribution: Debian, CentOS, windows 7 Posts: 866 Original Poster Rep: 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 //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.
09-04-2010, 07:13 AM   #4
Sergei Steshenko
Senior Member

Registered: May 2005
Posts: 4,481

Rep:
Quote:
 Originally Posted by jmc1987 ... 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++.

 09-04-2010, 07:46 AM #5 igadoter Member   Registered: Sep 2006 Location: wroclaw, poland Distribution: slack 12.2, debian-Trinity , openbsd Posts: 729 Rep: @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++.
 09-04-2010, 07:58 AM #6 MTK358 LQ 5k Club   Registered: Sep 2009 Posts: 6,443 Blog Entries: 3 Rep: 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.
09-04-2010, 03:04 PM   #7
Sergei Steshenko
Senior Member

Registered: May 2005
Posts: 4,481

Rep:
Quote:
 Originally Posted by igadoter @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.

09-04-2010, 06:49 PM   #8
wroom
Member

Registered: Dec 2009
Location: Sweden
Posts: 92

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