Just a quick update on my foray into computer science and my studying of the CS50 open course ware at http://cs50.tv/2011/fall/
I am currently working on the problem set for Week One (course starts on Week 0, like a computer would), called Pennies. You have to write a script in the C programming language that calculate a user’s input of the month, and is based on the old wisdom tale of would you rather have a bag of money or start with a penny and your pennies double every day for a month? I think this is a take on a similar tale I heard from my father when I was a kid. Only in his example, it had something to do with Ancient China and a guy asking the king as payment if he could have one grain of rice on the first square of a chess board and which would double each square on the chess board. Of course the king laughed at him wanting rice on a chess board instead of gold or money, but if you do the math… that is a fortune in rice!
Now I am attempting the Hacker editions of the problem sets, so I also in addition to writing a C program that computes the pennies problem I have to also create a program that prompts a user for a credit card number and then determines if that credit card is valid or not, using an algorithm created by Hans Peter Luhn who was a Computer Science pioneer at IBM. But I won’t get into this problem set yet, I will explain it later when I get it to work correctly.
A third problem in the Hacker Edition is to create some sort of vertical bar chart, but I haven’t got that far yet, so, for those curious here is the basic instructions of the pennies.c problem set (more details in the PDF if you go to the cs50.tv site):
Implement, in a file called pennnies.c, a program that first asks the user how many days there are in the month and then asks the user how many pennies he or she will receive on the first day of that month. The program should then calculate the amount that the user will have received in total by the end of the month (not just on the last day) if that amount is doubled on every day but the first, expressed not as pennies but as dollars and cents, with dollars formatted with commas every three digits. If the user does not type in 28, 29, 30, or 31 for the number of days in the month, the program should prompt the user to retry. If the user does not imput a positive integer for the first day’s number of pennies, the program should prompt the user to rety.
For instance, your program might behave as follows, whereby boldfaced text represents some user’s input.
jharvard@appliance (~/hacker1): ./pennies
Days in month: 32
Days in month: 31
Pennies on first day: 1