correction

V

Victor Bazarov

Rolf said:
I think it is.


I'd say the reason here is rather consistency. If you put the literal
on the left in one place, it's more consistent to do that everywhere.


Not sure what proof you mean.

I don't know. You made the claim, you're supposed to supply the proof.
I will be the judge of whether it looks like a proof to me or not.
I can't show you any production code
that does it, but I have seen it. Maybe it's not "quite common", but
neither is it as exotic as you made it sound.

I have *never* seen it in all millions of lines of production code
that passed in front of my eyes over the past twenty years. *Never*.
Not that it makes it necessarily exotic; for all I know, I've not even
seen one millionth of the code out there, and it is possible (although
not necessarily probable) that the code I didn't see is riddled with
expressions like that. But I doubt it.

Out of all posters here nobody came out saying "I do it all the time",
not even you. So, how could you call it "common"? OK, you say it's
not "quite common", but how common is it, then? "Not common", maybe?
"Quite uncommon"? "Unusual" (antonym for "usual")?...

V
 
J

Jim Langston

On Sep 18, 9:30 pm, "Victor Bazarov" <[email protected]>
wrote:
(e-mail address removed) wrote:
[..]
erm...how about if im using float...ant printf as %.0f..huhuhu
but
still i dont know how to saparate those digit as shown uhuhu
BTW, what's "uhuhu" or "huhuhu"?
[Snip previous discussion and unrelated code]
check out this code why it doesnt work huhuhu

#include <stdio.h>

int main(void)
{
float num;
int i, j, x ;

In C++ it is customary to declare variables as close to their first use as
possible. So get rid of the
int i,j,x;
since we're not using them yet.
printf("please key in any 5 digit number:");
scanf("%f",&num);

Since you are asking in a C++ newsgroup and not C, you should do it the C++
way.

#include <iostream>
at top.

std::cin >> num;
for ( i=0 ; 5>i ; ++i){

for ( int i = 0; i <= 5; ++i )
is more common.
for(j=0 ; i>j ; ++j){
printf(" ") ;
}

That looks okay.
for( x = j+1 ; 5 >= x ; ++x){

printf("%.0f", num);
}
putchar('\n');
}

But, you have a 5 digit number. First you want to print all 5 digits.
Which would be the number / 1
Then print 4 digits, number / 10
then print 3 digits, number / 100
see a pattern?

Consider:

std::cout << num / ( i * 10 );
Then you would want to print a space.
std::cout << " ";
Then you would want to print the remainder.
std::cout << num % ( i * 10 );
return 0;
}

Since you are asking in a C++ newsgroup, don't use printf, use std::cout.
Don't use scanf, use std::cin.
 
O

Old Wolf

huhu how to saparate those digin huhuhu can help???anyone?

What does 'huhu' and 'huhuhu' mean? I know an
Asian who uses those expressions (or even 'huhuhuhu'),
but when I ask her what they mean, she doesn't seem
to understand the question.
 
A

aslamhenry

What does 'huhu' and 'huhuhu' mean? I know an
Asian who uses those expressions (or even 'huhuhuhu'),
but when I ask her what they mean, she doesn't seem
to understand the question

huhu is like a crying sound.....
 
A

anon

I do this all the time for that reason.
I don't know. You made the claim, you're supposed to supply the proof.
I will be the judge of whether it looks like a proof to me or not.


Out of all posters here nobody came out saying "I do it all the time",
not even you. So, how could you call it "common"? OK, you say it's
not "quite common", but how common is it, then? "Not common", maybe?
"Quite uncommon"? "Unusual" (antonym for "usual")?...

I do it sometimes. Not sure why. Probably when I get limits like for
example this:
0 <= a <= 0.6
then I would do:
if ( ( 0.0 <= a ) && ( a <= 0.6 ) )
....
 
G

Guest

Out of all posters here nobody came out saying "I do it all the time",
not even you. So, how could you call it "common"? OK, you say it's
not "quite common", but how common is it, then? "Not common", maybe?
"Quite uncommon"? "Unusual" (antonym for "usual")?...

V
C++ coding guidelines where I am working state that "In logical statements
with constants, the constant should be on the left side of the conditional
expression".
And the question "Do I have a constant there" before typing the logical
statement has never been harmful to me.
 
J

Joe Greer

It's not the matter of "dropping" the '='. It's actually because of
using '=' for equality, which they learned from Basic, Pascal, and so
on. Pascal has ':=' for assignment. Basic... well, let's not discuss
Basic here, shall we?

Yes, it is. The convention is to prevent an accidental assignment.
This is unfortunately a speculation of somebody who does not use that
form of comparison (am I right?) I hoped Rolf would give some proof
of his "quite common" assertion.

No, it is officially the rule here for the very reason I mentioned.
Fortunately, it isn't enforced, but that is the justification for the rule.

joe
 
B

Bo Persson

Émeric Dupont wrote:
:: On Tue, 18 Sep 2007 22:23:31 +0200, Victor Bazarov
::
::: Out of all posters here nobody came out saying "I do it all the
::: time", not even you. So, how could you call it "common"? OK,
::: you say it's not "quite common", but how common is it, then?
::: "Not common", maybe? "Quite uncommon"? "Unusual" (antonym for
::: "usual")?...
:::
::: V
:: C++ coding guidelines where I am working state that "In logical
:: statements with constants, the constant should be on the left side
:: of the conditional expression".
:: And the question "Do I have a constant there" before typing the
:: logical statement has never been harmful to me.

Another reasonable guideline would be not using constants (literals)
in logical statements. They should first be given a readable name in a
const declaration.



Bo Persson
 
V

Victor Bazarov

Bo said:
Another reasonable guideline would be not using constants (literals)
in logical statements. They should first be given a readable name in a
const declaration.

Either way, I find that requirement (to put constants on the left)
quite unreasonable. The readability (which is undoubtedly subjective)
suffers dramatically AFA I'm concerned. Compare

double x = someexpreesion;
if (x >= someconstant) {
do_something_with(x);
}

(reads "define and initialise x. if x is at or above some constant,
do something with it") and

double x = someexpression;
if (someconstant <= x) {
do_something_with(x);
}

(reads "define and initialise x. if some constant is at or below x,
do something with x"). Awkward; the second sentence brings attention
to "some constant" away from "x". Not the way we write in normal
logic statements.

Now, let's follow the justification to the extreme. Imagine that
I have a class that defines both << and < operator with an integer
as the right-hand side argument:

class Foo {
public:
Foo(int);
Foo operator << (int value) const;
operator void* () const; // so I can do 'while(foo)'
};

bool operator < (Foo const&, int value);
bool operator > (Foo const&, int value);

Now, in order to prevent a possible problem of losing a single
less-than sign in this situation

Foo foo;
...
if (foo << 5)

(so it becomes, erroneously

if (foo < 5)

), I should be implementing the right shift operator

Foo operator >> (int, Foo const&);

so I can write

if (5 >> foo)

instead, correct? But then, what prevents me from losing one
'greater-than' sign here so it suddenly becomes

if (5 > foo)

which I tried avoiding in the first place?

So, "consistency" has to have its limits. And in my book, the
consistency should be "always write the correct operator" because
no tricks are good enough to avoid all possible mistakes.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,294
Latest member
HollieYork

Latest Threads

Top