Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Code won\'t run. In this exercise, you will practice writing a function that use

ID: 675111 • Letter: C

Question

Code won't run.

In this exercise, you will practice writing a function that uses pointers as the function parameters. A group of elementary school kids are learning how to use coins (i.e., quarters, dimes, nickels, and pennies) to represent any amount of money. To make it simple for the kids, the total amount of money is in cents and could be any integer from 0 to 1000 (inclusive). Your job is to write a function and help them to validate the results. Please try to use the high value coins as much as possible. That is, always use quarters first, then dimes, nickels, and last pennies. After you write the function, you should call it in the driver program to test it. The printf statements should print the results directly. You are not allowed to change anything in the main function except the addition of a function call

#define _CRT_SECURE_NO_WARNINGS
#include


void num_quarters(int cents, int *quarters)
{
   quarters = cents / 4;
}
void numOfDimes(int &quarters, int cents, int &dimes)
{
   quarters = cents / 10;
}
void numOfNickels(int &quarters, int cents, int *nickel)
{
   quarters = cents / 5;
}
void numOfPennies(int &quarters, int cents, int *pennies)
{
   quarters = pennies;
}


int main(int argc, char *argv[])
{
   int totalCents; int numQuarters = 0, numDimes = 0, numNickels = 0, numPennies = 0;
   printf("Please enter the total number of cents (0-1000): ");
   scanf("%d", &totalCents);
   numOfQuarters();
   numOfDimes();
   numOfNickels();
   numOfPennies();

   printf("The total number of quarters is: %d ", numQuarters);
   printf("The total number of dimes is: %d ", numDimes);
   printf("The total number of nickels is: %d ", numNickels);
   printf("The total number of pennies is: %d ", numPennies);
   return 0;
}

Explanation / Answer

Please find the working code as per the requirements:

#define _CRT_SECURE_NO_WARNINGS
void numOfQuarters(int *cents, int *quarters)
{
*quarters = *cents / 25;
*cents = *cents -(*quarters *25);
}

void numOfDimes(int *cents, int *dimes)
{
*dimes = *cents / 10;
*cents = *cents -(*dimes *10);
}
void numOfNickels(int *cents, int *nickels)
{
*nickels = *cents / 5;
*cents = *cents -(*nickels *5);
}
void numOfPennies(int *cents, int *pennies)
{
*pennies = *cents;
}
int main(int argc, char *argv[])
{
int totalCents; int numQuarters = 0, numDimes = 0, numNickels = 0, numPennies = 0;
printf("Please enter the total number of cents (0-1000): ");
scanf("%d", &totalCents);
numOfQuarters(&totalCents,&numQuarters);
numOfDimes(&totalCents, &numDimes);
numOfNickels(&totalCents,&numNickels);
numOfPennies(&totalCents,&numPennies);
printf("The total number of quarters is: %d ", numQuarters);
printf("The total number of dimes is: %d ", numDimes);
printf("The total number of nickels is: %d ", numNickels);
printf("The total number of pennies is: %d ", numPennies);
return 0;

}