Review: Functions (b)
Instructions: Think about each question and write the answer in your notebook.
Study this program, then answer the questions at the bottom of this page.
#include<stdio.h>
float Tax(float price)
{
return (price + (price * 0.08));
}
void main( )
{
float price;
char choice;
float total;
printf("Do you want the tape (type t) or cd (type c)? ");
scanf(" %c", &choice);
switch(choice)
{
case 't':
price = 7.95;
Tax(price);
break;
case 'c':
price = 12.50;
Tax(price);
break;
default:
printf("You've made an error!\n");
break;
}
total = Tax(price);
printf("The price is $%.2f.\nWith tax, the total is $%.2f.", price, total);
}
Questions
1. How many user-defined functions are in this program?
2. What is the name of the passed variable?
3. What is the name of the variable that stores the returned value?
4. If the viewer types 't', what will the printf statement say?
5. If the viewer types 'c', what will the printf statement say?
6. If the viewer types 'p', what will the printf statement say?