Create a project called Daily19. Add the given daily19.c into the project and us
ID: 3763106 • Letter: C
Question
Create a project called Daily19. Add the given daily19.c into the project and use it as a driver. 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. Remember to use a meaningful name for the function and variables. Define any constants when needed.
__________________________________________________________________________________________________
#include <stdio.h>
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);
//call your function below
//print the result to the screen
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;
}
==============================================================================================
This is what I have but it only returns zero for each coin meaning there values were never changed.
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#include<stdio.h>
void numOfQuarters(int &totalCents, int &quarters);
void numOfDimes(int &totalCents, int &dimes);
void numOfNickels(int &totalCents, int &nickel);
void numOfPennies(int &totalCents, int &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);
//call your function below
//print the result to the screen
void numOfQuarters(int &totalCents, int &numQuarters);
void numOfDimes(int &totalCents, int &numDimes);
void numOfNickels(int &totalCents, int &numNickel);
void numOfPennies(int &totalCents, int &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;
}
void numOfQuarters(int &totalCents, int &numQuarters)
{
numQuarters = totalCents / 4;
}
void numOfDimes(int &totalCents, int &numDimes)
{
numDimes = totalCents / 10;
}
void numOfNickels(int &totalCents, int &numNickels)
{
numNickels = totalCents / 5;
}
void numOfPennies(int &totalCents, int &numPennies)
{
numPennies = numPennies;
}
Explanation / Answer
// you are experiencing errors or incorrect values because of following mitakes
1. you declare functions wrongly. Parameters of functions should be pointers because you want to pass value by reference but you mention address as parameters.
2. your function calling statements are wrong that why you are getting 0 everytime because function did not get call and values do not get updated.
3. In function defination also you have written incorrect parameters and logic. For quateres , 1 quateres=25cents not 4 cents.
4. you have given incorrect definations of functions.
#include<stdio.h>
void numOfQuarters(int *totalCents, int *quarters);
void numOfDimes(int *totalCents, int *dimes);
void numOfNickels(int *totalCents, int *nickel);
void numOfPennies(int *totalCents, int *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);
//call your function below
//print the result to the screen
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);
system("PAUSE");
return 0;
}
void numOfQuarters(int *totalCents, int *numQuarters)
{
*numQuarters = *totalCents / 25;
}
void numOfDimes(int *totalCents, int *numDimes)
{
*numDimes = *totalCents / 10;
}
void numOfNickels(int *totalCents, int *numNickels)
{
*numNickels = *totalCents / 5;
}
void numOfPennies(int *totalCents, int *numPennies)
{
*numPennies = *totalCents;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.