Question

. Programing Just with #include <stdio.h> Once again we will create a program that tells us how many months we need to save t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Explanation:

here is the funciton calculate takin 4 arguments for goal , current, monthly and the months as reference to update it .

Then using if else, it checks if goal is reached or not, until the goal is not reached, it keeps increasing the current value and incrementing the months by 1.

feel free to comment if you need any help!

Code:

#include <stdio.h>

void calculate(int goal, int current, int monthly, int* months)
{
if(goal<=current)
{
return;
}
else
{
(*months)++ ;
calculate(goal, current+monthly, monthly, months);
}
}

int main()
{
int goal, current, monthly, months = 0;
printf("Which amount are you trying to reach? ");
scanf("%d", &goal);
  
printf("How much money do you currently have? ");
scanf("%d", &current);
  
printf("How much will you put aside every month? ");
scanf("%d", &monthly);
  
calculate(goal, current, monthly, &months);
  
printf("The number of months you'll need is: %d", months);
return 0;
}

Output:

Which amount are you trying to reach? 1000 How much money do you currently have? 100 How much will you put aside every month?

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!

Add a comment
Know the answer?
Add Answer to:
. Programing Just with #include <stdio.h> Once again we will create a program that tells us...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Once again we will create a program that tells us how many months we need to...

    Once again we will create a program that tells us how many months we need to save to reach a goal. This time however, using recursive functions. The guidelines are the following:  In main, ask the user for the initial amount, the goal and the “monthly amount” (the constant amount of money that will be put aside every month).  Once you have these values you should call your function. Your function should not return anything and it should...

  • Programing C Just with #include <stdio.h> We will create a singly linked list of 7 nodes....

    Programing C Just with #include <stdio.h> We will create a singly linked list of 7 nodes. Then, the user will tell us whether to print the “odd-placed” nodes or the “even-placed” nodes. For example, if I had a list of 5 nodes like below, and the user specifies for the odd nodes to be printed, my program would print the values in nodes nl and n3. If the user instead indicated for the even nodes to be printed, my program...

  • USE C Programming LANGUAGE ONLY PLEASE. We use <stdio.h> if that helps. For the following problems,...

    USE C Programming LANGUAGE ONLY PLEASE. We use <stdio.h> if that helps. For the following problems, create the prototype function, calling function “int main()”, and function. So the function prototype, function call, and function header/body should be seen in the answer. The processor directive is not needed. Show a sample call from the int main() function for all problems. If you can for the first one please show proof that it has no errors. 1. Write a function called DisplayColumbiaUniversity...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops...

    Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops. A synthetic linear recursive procedure for this problem is provided in Code Fragment 1. A recursive function such as the one described is intuitive and easily understandable. On calling myRecursion(input), the execution first checks for the stopping condition. If the stopping condition is not met, then operations inside the recursive call are performed. This can include operations on local variables. The operations inside the function...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • Can someone please complete the "allTheQueensAreSafe" function? #include <stdio.h> #include <stdlib.h> void printBoard(int *whichRow, int n)...

    Can someone please complete the "allTheQueensAreSafe" function? #include <stdio.h> #include <stdlib.h> void printBoard(int *whichRow, int n) {    int row, col;    for (row = 0; row < n; row++)    {        for (col = 0; col < n; col++)        {            printf("%c", (whichRow[col] == row) ? 'Q' : '.');        }        printf("\n");    }    printf("\n"); } int allTheQueensAreSafe(int *whichRow, int n, int currentCol) {    // TODO: Write a function that returns 1 if all the queens represented by    // this array are safe (i.e., none...

  • ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive...

    ld ts biovs Part II: Analysis of recursive algorithms is somewhat different from that of non-recursive algorithms. We are very much interested in how many times the method gets called. The text refers to this as the number of activations. In inefficient algorithms, the number of calls to a method grows rapidly, in fact much worse than algorithms such as bubble sort. Consider the following: public static void foo ( int n ) { if n <=1 ow ura wor...

  • Python 3.8.0 homework help We know a thermometer tells us the ambient temperature. However, we also...

    Python 3.8.0 homework help We know a thermometer tells us the ambient temperature. However, we also know that depending on other conditions, like humidity or wind velocity, can affect how warm or cold the air temperature feels. The wind chill temperature, Twc, is the temperature you feel on your exposed skin due to the wind velocity, v. The following equation can be used: Twc = 35.74 +0.6215TA-35.75v0.16 + 0.4275T (v0.16), TA= Temperature in Fahrenheit V = velocity in miles per...

  • PYTHON Fractal Drawing We will draw a recursively defined picture in this program. Create a function...

    PYTHON Fractal Drawing We will draw a recursively defined picture in this program. Create a function def fractal(length, spaces). This function will print out a certain number of stars * and spaces. If length is 1 print out the number of spaces given followed by 1 star. If the length is greater than one do the following: Print the fractal pattern with half the length and the same number of spaces. Print the number of spaces given followed by length...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT