Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Yes, but who expects the words "tens" and "ones" to stand for truth-values?

A C programmer.

Seriously. If you aren't looking at the expressions as a C programmer, then you're not looking at it the way the C compiler does, and that can lead to problems.

More specifically, a C programmer should know that there is no such thing as a "truth-value" in C. There are only zero and non-zero bit-patterns in the few basic types.
 
I doubt that my transformation improves program readability, and I'm sure many of us here have taken some philosophy courses. I wasn't showing off. And I certainly wasn't looking down on anyone. I the first post where I typed "!(p || q)", I grinned. Unfortunately, I sometimes sound like a show-off when I don't mean to do that.

Some wires must have gotten crossed on one or both sides of this conversation. I wasn't sure what part of my comment you were responding to with the explanation of some equivalences, etc. so I was just commenting that I wasn't disagreeing with your assertion, just sticking up for arguable readability of my original expression. I didn't think you were bragging, etc. I was just expressing that while I probably couldn't do some logical proofs at all or perhaps not as quickly as you might be able to, it wasn't my first time at the logic rodeo. You likely weren't implying that it was, I just wasn't clear about the intent of your post.

Anyway, good times all around. Over 100 posts on this thread. That's a lot of posts for outputting english words for a few arabic numerals.

-Lee
 
My suggestion, which naples98 was clarifying, was to change that into something like:

Code:
	first_number = number / 10 ;
	second_number = number % 10 ;
	
	switch (first_number) {
		case 9: printf ("ninety"); break;
		case 8: printf ("eighty"); break;
		case 7: printf ("seventy"); break;
		case 6: printf ("sixty"); break;
		case 5: printf ("fifty"); break;
		case 4: printf ("forty"); break;
		case 3: printf ("thirty"); break;
		case 2: printf ("twenty"); break;
		}

	if(first_number != 0 && second_number != 0) {
		printf("-");
	}

	switch (second_number) {
		case 9: printf ("nine"); break;
		case 8: printf ("eight"); break;
		case 7: printf ("seven"); break;
		case 6: printf ("six"); break;
		case 5: printf ("five"); break;
		case 4: printf ("four"); break;
		case 3: printf ("three"); break;
		case 2: printf ("two"); break;
		case 1: printf ("one"); break;
		}
	printf("\n");

This also incorporates balmw's idea re: the - and single digit numbers.

Also, you might want to add some error checking as we have discussed previously. If the user enters -234 or 2114 the code won't work properly. You ask them to enter a 2 digit number. If they disobey (maybe you can be lenient about a 1 digit number) you should tell them so. Just check if what's entered is < 1 or > 99. You didn't specify the number must be positive, but obviously the code only handles positives right now.

-Lee[/QUOTE]

Lee, sorry to bother. I wanted to remove my dashes because they weren't working as you all have previously mentioned, and I wanted to use the "if" code you inserted above for dashes. However, my code compiles fine when I comment out the new "if" statement for dashes, but when I add it back in, as you suggest, it won't compile. I"ve included my terminal error and code below. Yours and mine are identical. Why won't it compile now? I don't see any typos, and I've read each character 10 times at least!

Code:
Scott-Deans-MacBook-Pro:documents scottdean$ gcc ~/documents/number2number.c
/Users/scottdean/documents/number2number.c: In function ‘main’:
/Users/scottdean/documents/number2number.c:74: error: expected ‘)’ before ‘!’ token


Code:
	first_number = number / 10 ;
	    second_number = number % 10 ;
	
	switch (first_number) {
		case 9: printf ("ninety"); break;
		case 8: printf ("eighty"); break;
		case 7: printf ("seventy"); break;
		case 6: printf ("sixty"); break;
		case 5: printf ("fifty"); break;
		case 4: printf ("forty"); break;
		case 3: printf ("thirty"); break;
		case 2: printf ("twenty"); break;
		}
		
    if(first_number ! = 0 && second_number ! = 0) {
		printf ("-") ;	
	}	
		
	switch (second_number) {
		case 9: printf ("nine"); break;
		case 8: printf ("eight"); break;
		case 7: printf ("seven"); break;
		case 6: printf ("six"); break;
		case 5: printf ("five"); break;
		case 4: printf ("four"); break;
		case 3: printf ("three"); break;
		case 2: printf ("two"); break;
		case 1: printf ("one"); break;
		}
	printf ("\n") ;
 
A C programmer.

Seriously. If you aren't looking at the expressions as a C programmer, then you're not looking at it the way the C compiler does, and that can lead to problems.

More specifically, a C programmer should know that there is no such thing as a "truth-value" in C. There are only zero and non-zero bit-patterns in the few basic types.
I agree with you chown33. I also know of other expressions that some C programmers write routinely, although those expressions don't look boolean. Professor Allan Nash, for example, would write "while (fgets(line, sizeof(line), input)" instead of while "(fgets(line, sizeof(line), input) != NULL)." I understand both expressions. But if your computer checks the first expression with a program called "splint," not "lint," the machine will complain that "while (fgets(line, sizeof(line), input)" is nonboolean. There aren't an truth-values at runtime, and a C programmer should see a program the way the computer sees it when it compiles that program. My question about "(tens && ones)" was about style and about what seems intuitive, not about how the computer saw that expression.
 
Yeah, actually I just picked up a tip. It was there, but I didn't grasp it. Then I read it again and had an "Ohhhh I get it" moment.

I was beginning to wonder if you were feeling overwhelmed by the back and forth!

Since some were able to grab the Xcode 4 GM before it was pulled I feel I can make the following comment …

You're going to like Xcode 4's as you type syntax checking and error messages. If something is missing or out of scope the editor lets you know immediately!
 
I was beginning to wonder if you were feeling overwhelmed by the back and forth!

Since some were able to grab the Xcode 4 GM before it was pulled I feel I can make the following comment …

You're going to like Xcode 4's as you type syntax checking and error messages. If something is missing or out of scope the editor lets you know immediately!

What do you mean Xcode 4 GM before it was pulled? I downloaded Xcode ( I have 3.2). but what does GM refer to? What/why was it pulled? Discontinued? Had problems?

Should I use my Xcode as the editor, will it help me learn more, or am I better off sticking with Text Wrangler and Terminal for a few more months til' I get the gist?
 
cybrscot,

!= is one operator just like == is. Remember that ! and = are also valid operators, so, if you mean != you can't write ! = as it's not the same thing.
 
cybrscot,

!= is one operator just like == is. Remember that ! and = are also valid operators, so, if you mean != you can't write ! = as it's not the same thing.

:eek::eek::eek:
Darn, I'm cursing myself for that! No I didn't realize the spacing was important, I just figured the compiler read from left to right associative, and there is nothing in between. I like to space everything for readability, but now I see that sometimes that can't be done with everything.

Man I'm kicking myself for that. I thought we wrote identically, just didn't know. Sure I've seen that operator already, but the book didn't come out and say that there cannot be a space between ( I don't have a teacher, learning on my own). Although the book has it typed correctly, I didn't think that the spacing (or lack thereof) was intentional. I figured we have is and is not, or = and !=, but I thought wrongly that != and ! = were the same because of associativity.

Thanks so much for pointing that out. Man.... the details! The book left that as an assumption I guess. Probably assumed a professor would point that out.
 
Some wires must have gotten crossed on one or both sides of this conversation. I wasn't sure what part of my comment you were responding to with the explanation of some equivalences, etc. so I was just commenting that I wasn't disagreeing with your assertion, just sticking up for arguable readability of my original expression. I didn't think you were bragging, etc. I was just expressing that while I probably couldn't do some logical proofs at all or perhaps not as quickly as you might be able to, it wasn't my first time at the logic rodeo. You likely weren't implying that it was, I just wasn't clear about the intent of your post.

Anyway, good times all around. Over 100 posts on this thread. That's a lot of posts for outputting english words for a few arabic numerals.

-Lee
Thanks, Lee. Sadly, I've misinterpreted most of what people me in this thread today. I think hyper-analytically. But sometimes my feelings and my impulsiveness cloud my judgment. I learn best by hearing.

I read voraciously when I studied computer science in college. Since the interested me, I read extra books that my professor didn't assign. So in class, I sometimes brought up topics that were new to the other students.

After a class about data structures, a professional systems programmer told me, "Those of us who are more intelligent than others need to be careful about how we show it." Ever since then I've worried about whether I seem to brag when I talk about something I've learned. You guys are the CS experts. I'm better at dogmatic theology.
 
I was beginning to wonder if you were feeling overwhelmed by the back and forth!

Since some were able to grab the Xcode 4 GM before it was pulled I feel I can make the following comment …

You're going to like Xcode 4's as you type syntax checking and error messages. If something is missing or out of scope the editor lets you know immediately!


Yes, sometimes the chatter gets way over my head. In the very beginning of my learning, I couldn't even understand what anybody meant when they answered me, as the lingo and jargon made no sense. I read their help and I was like, what?? After my problems have been solved (as I mentioned yesterday), sometimes the thread continues as folks debate style and different schools of thought I guess. But it's interesting and people still post stuff that I can understand Also, this is a language, so trying to at least read the posts is like the immersion technique for learning a foreign language. I may not understand most of it, but the next time I hear it, it will no longer be the first time, and again and again, or ++ if you like!!
 
:eek::eek::eek:
Darn, I'm cursing myself for that! No I didn't realize the spacing was important, I just figured the compiler read from left to right associative, and there is nothing in between. I like to space everything for readability, but now I see that sometimes that can't be done with everything.

Use blank space to improve readability, but group things together when they belong together. To me
Code:
if ( ones != 0 && tens != 0 ) {...
is much easier to read than
Code:
if(ones != 0 && tens != 0){...
but maybe that is just me. The extra time it takes to write easy-to-read code is trivial compared to the amount of time it takes to figure our what is wrong with obtusely written code.
 
Man I'm kicking myself for that. I thought we wrote identically, just didn't know. Sure I've seen that operator already, but the book didn't come out and say that there cannot be a space between ( I don't have a teacher, learning on my own). Although the book has it typed correctly, I didn't think that the spacing (or lack thereof) was intentional. I figured we have is and is not, or = and !=, but I thought wrongly that != and ! = were the same because of associativity.
Maybe someone needs to revise some programming languages to improve their readability. In Prolog, a semicolon means "or," and "\+" means "can't prove." I've read some programs, or maybe some pseudocode," where a right-arrow was an assignment operator. In what I'd read, "x -> 1" meant what "x = 1" means in C. For years, I read textbooks full of pseudocode where "<-" was an assignment operator. "X <- Y" made sense to me, but "X -> Y" confused me.
 
... I'm better at dogmatic theology.

Eminently qualified for a Mac forum, no? <paste smiley here>


"X <- Y" made sense to me, but "X -> Y" confused me.
I've seen that notation in processor manuals. I usually read it as "copied to". Sometimes the source is parenthesized: (X) -> Y, read as "contents of X copied to Y", where X and Y are register names.
 
:eek::eek::eek:
Darn, I'm cursing myself for that! No I didn't realize the spacing was important, I just figured the compiler read from left to right associative, and there is nothing in between. I like to space everything for readability, but now I see that sometimes that can't be done with everything.

Don't worry about it, it will stick sooner rather than later if you keep at it.
 
Last edited:
I thought wrongly that != and ! = were the same because of associativity.

Maybe it helps to think of it this way
Code:
(a != b)
is shorthand for
Code:
!(a == b)
and not
Code:
!(a = b)
.

There are plenty of operators like this in C like the increment/decrement operators "++" and "--" and the shorthand assignment operators "+=", "-=", "*=", "/=", "%=", ....

See here for a more complete treatment: http://www.exforsys.com/tutorials/c-language/c-operators.html

B
 
Eminently qualified for a Mac forum, no? <paste smiley here>
Maybe I'm qualified because I know how to program reasonably well. But I'm not a Mac expert.

The best news? I still now how to paste a smiley. <:)>


I've seen that notation in processor manuals. I usually read it as "copied to". Sometimes the source is parenthesized: (X) -> Y, read as "contents of X copied to Y", where X and Y are register names.
Thanks. Now both symbols make sense to me. There's still something I'll never understand, though. In Cobol, the word "move" means "copy" and the word "copy" means "include."
 
There's still something I'll never understand, though. In Cobol, the word "move" means "copy" and the word "copy" means "include."

Forsooth, methinks yon COBOL useth words in ancient ways,
Which mortals rarely fathom (nay, nor speaketh) nowadays;
For now 'tis more Objective-C'mly to "import"
When one doth reference code from t'other's court.
 
Last edited:
Forsooth, methinks yon COBOL useth words in ancient ways,
Which mortals rarely fathom (nay, nor speaketh) nowadays;
For now 'tis more Objective-C'mly to "import"
When one doth reference code from t'other's court.

As though it was, like, a whole 'nother language or something.
 
Forsooth, methinks yon COBOL useth words in ancient ways,
Which mortals rarely fathom (nay, nor speaketh) nowadays;
For now 'tis more Objective-C'mly to "import"
When one doth reference code from t'other's court.
Aha! Now I know who can teach me Shakespeare. ;) Meanwhile, each time I post to this thread, Lee's avitar appears on my screen before the post does. It's as though I keep seeing the ghost of Hamlet's father. :)
 
There's still something I'll never understand, though. In Cobol, the word "move" means "copy" and the word "copy" means "include."

This reminded me that when the C++ language was new someone suggested Object-Oriented COBOL and that it be named "ADD 1 TO COBOL GIVING COBOL." :)
 
This reminded me that when the C++ language was new someone suggested Object-Oriented COBOL and that it be named "ADD 1 TO COBOL GIVING COBOL." :)
Years ago, I tutored a student who asked me to help him debug his COBOL program that made the computer repeat a report's last line. After I stared at the program for 10 or 15 minutes, I discovered that he called a paragraph recursively when the language supposedly doesn't support recursion. I explained the problem and told him that he needed to revise the recursive paragraph. He replied he didn't want to do that. Thank God I didn't mention that we were using an OS that let you edit output in the print queue. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.