Hello <---- My Project!
Suffice it to say, no matter how you compile or execute this program, it only ever prints hello, world
. Let’s personalize it a bit, just as we did in class.
Modify this program in such a way that it first prompts the user for their name and then prints hello, so-and-so
, where so-and-so
is their actual name.
Mario <---- My Project!
Toward the beginning of World 1-1 in Nintendo’s Super Mario Brothers, Mario must hop over adjacent pyramids of blocks, per the below.
Let’s recreate those pyramids in C, albeit in text, using hashes (#
) for bricks, a la the below. Each hash is a bit taller than it is wide, so the pyramids themselves are also be taller than they are wide.
Example
Here’s how the program might work if the user inputs 4
when prompted:
$ ./mario
Height: 4
# #
## ##
### ###
#### ####
Credit <---- My Project!
A credit (or debit) card, of course, is a plastic card with which you can pay for goods and services. Printed on that card is a number that’s also stored in a database somewhere, so that when your card is used to buy something, the creditor knows whom to bill. There are a lot of people with credit cards in this world, so those numbers are pretty long: American Express uses 15-digit numbers, MasterCard uses 16-digit numbers, and Visa uses 13- and 16-digit numbers. And those are decimal numbers (0 through 9), not binary, which means, for instance, that American Express could print as many as 10^15 = 1,000,000,000,000,000 unique cards! (That’s, um, a quadrillion.)
Actually, that’s a bit of an exaggeration, because credit card numbers actually have some structure to them. All American Express numbers start with 34 or 37; most MasterCard numbers start with 51, 52, 53, 54, or 55 (they also have some other potential starting numbers which we won’t concern ourselves with for this problem); and all Visa numbers start with 4. But credit card numbers also have a “checksum” built into them, a mathematical relationship between at least one number and others. That checksum enables computers (or humans who like math) to detect typos (e.g., transpositions), if not fraudulent numbers, without having to query a database, which can be slow. Of course, a dishonest mathematician could certainly craft a fake number that nonetheless respects the mathematical constraint, so a database lookup is still necessary for more rigorous checks.
Implementation
In a file called credit.c
in a ~/pset1/credit/
directory, write a program that prompts the user for a credit card number and then reports (via printf
) whether it is a valid American Express, MasterCard, or Visa card number, per the definitions of each’s format herein. So that we can automate some tests of your code, we ask that your program’s last line of output be AMEX\n
or MASTERCARD\n
or VISA\n
or INVALID\n
, nothing more, nothing less.
Example
$ ./credit
Number: 4003600000000014
VISA