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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-04-2010, 04:58 AM
|
#1
|
|
Member
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows xp
Posts: 776
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 <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
|
|
|
|
09-04-2010, 05:21 AM
|
#2
|
|
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, 05:51 AM
|
#3
|
|
Member
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows xp
Posts: 776
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 <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.
|
|
|
|
09-04-2010, 06:13 AM
|
#4
|
|
Senior Member
Registered: May 2005
Posts: 4,386
|
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, 06:46 AM
|
#5
|
|
Member
Registered: Sep 2006
Location: wroclaw, poland
Distribution: slack 12.2, debian-Trinity , openbsd
Posts: 675
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, 06:58 AM
|
#6
|
|
LQ 5k Club
Registered: Sep 2009
Distribution: Arch x86_64
Posts: 6,443
|
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, 02:04 PM
|
#7
|
|
Senior Member
Registered: May 2005
Posts: 4,386
|
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, 05:49 PM
|
#8
|
|
Member
Registered: Dec 2009
Location: Sweden
Posts: 50
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:00 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|