Thursday, November 3, 2011

Learning C - C Primer Plus

I thought I would post some chapter review programs from chapters I'm reading in C Primer by Stephen Prata. This won't mean anything to anyone unless they know C programming. I'm basically putting it here so others can learn from what I've done and partly because I think a computer program is beautiful. Sort of in an artistic way. The characters and code seem like a picture to me.

This C program converts Centimeters to Feet and Inches:

//*************************************************
#include <stdio.h>
#define CMPERFT 30.48

float cm,ft,in;

int main (void) {
printf("Enter a height in centimeters (<=0 to quite): ");
scanf("%f", &cm );

while (cm > 0) {
ft = cm/CMPERFT;
in = (ft - (int)ft) * 12; //You can't find a remainder of a float with modulus.So use Cast
printf("\n%0.2f cm = %d feet, %0.3f inches\n", cm, (int)ft ,in);
printf("Enter a height in centimeters (<=0 to quite): ");
scanf("%f", &cm );
}

return 0;
}


//************************************************

Thursday, October 27, 2011

Finally Cut Comcast Cable

Well, I finally got fed up with Comcast Cable TV's high prices and cut the cable.
Though they'll never know. I told them I was moving so I wouldn't incur any additional fees.
Soon I'll be placing an Antenna in the attic for those times when I want the TV to make some noise. But other than that, I'll get what I want off of the internet. I've had cable since 1985 when I got my fist apartment. They've made a fortune off of me if you think the average over those 26 years has been about $40 a month, that comes to about $12,480. That's a lot for TV that is paid for by commercials anyway.
So long Comcast, you suck.... have been sucking for 26 years....money out of my wallet.
No more, good riddens.


Saturday, August 13, 2011

invalid literal for int() with base 10:

So I'm learning Python programming in my spare time.
For two hours I was stuck on this simple error:
invalid literal for int() with base 10:

Turns out, if you input a string number like "4.0" and you want the integer of it,
you must first make the string a float, and then make the float an integer.
"4.0" > float("4.0") > int(4.0) is the path.

So
>>>int("4.0") #this will give you an error
>>>int(float("4.0")) #this will work and give you >>>4

The reason I think this is necessary is because Python wants you to verify that you
know you are converting a float to an integer. It doesn't want to assume you know that.


Monday, May 2, 2011

Obama Can Do No Right

I believe President Obama could single-handedly find a cure for cancer, and people would bash him for killing off an entire industry.
It's true, you know it's true.