Solution for Exercise 19-23

ex1923

#include <stdio.h>

void discount(float *a);

int main()
{
    float price = 42.99;

    printf("The item costs $%.2f\n",price);
    discount(&price);
    printf("With the discount, that's $%.2f\n",price);
    return(0);
}

void discount(float *a)
{
    *a = *a * 0.90;
}

Notes

* Line 17 may look odd because the * character is used as both the pointer and multiplication operators. Such things happen often in C. In fact, the line could be re-written to look like this:

Or even like this when you squeeze out the white space:

Above, it looks like I've made up a new operator, *a*. But it's actually two items: *a and *=.