Homework 17: Pointer arguments
Name: _____________________________________________ Alpha: ___________________
Describe help received: ________________________________________________________
- Due before class on Monday, February 27
- This homework contains code to be submitted electronically.
Put your code in a folder called
hw17and submit using the204subcommand. - This is an electronic homework and you do not need to print out anything to turn in during class.
Assignment
- Required reading: Section 3 (passing pointers to functions) from the Unit 5 notes,
-
Below is a `main` function for a program that reads in a dollar
amount like `$3.50` and converts it into dollars and cents:
What's missing from this program is the prototype and definition for the functionint main() { printf("Enter amount: "); fflush(stdout); double amt; if (scanf(" $%lg", &amt) != 1) { printf("ERROR: must enter something like $3.50\n"); return 1; } // FUNCTION CALL HERE! int dollars; int cents; split(amt, &dollars, ¢s); printf("That's %i dollars and %i cents.\n", dollars, cents); return 0; }splitwhich takes in a total amount as a double and splits it into twoints for dollars and cents.
Complete the program by providing a prototype and definition forsplitand submit your code in a file calledcents.c.Examples:
roche@ubuntu$./centsEnter amount:$3.50That's 3 dollars and 50 cents.roche@ubuntu$./centsEnter amount:$2That's 2 dollars and 0 cents.roche@ubuntu$./centsEnter amount:$81.67That's 81 dollars and 67 cents.