Question

An Amish farmer has determined that the number of cows he owns will double every year....

An Amish farmer has determined that the number of cows he owns will double every year. He only has room on his farm for a certain number of cows. He would like you to write a program that will determine the number of years it will take to reach the maximum number of cows. The main function should prompt the user to enter two integer values; the current number of cows and the maximum number of cows. These values should be passed by value to a function called maxCows. The maxCows function will contain a loop that will double the number of cows until the maximum number of cows is reached, displaying the number of cows with each iteration of the loop. The maxCows function will return the number of years that it took to reach maximum cow capacity to the main function, where that value will be displayed to the user.

WRITE A C PROGRAM PLEASE

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

Answer: here is the answer for your question :

CODE IN C:

#include<stdio.h>
#include<string.h>
void maxCows(int c_cows, int max_cows)
{
int years=0;
while(c_cows*2<=max_cows)
{
c_cows=c_cows*2;
years++;
printf("In year %d , number of cows is %d \n",years,c_cows);
}
printf("maximum number of cows will be reached in %d years",years);
}

int main(void)
{
int current_cows=0;
int max_capacity;
printf("Enter the current cows that you have: ");
scanf("%d",&current_cows);
printf("Enter the maximum capacity : ");
scanf("%d",&max_capacity);
maxCows(current_cows,max_capacity);

return 0;
}

------------------------------------------------------------------------------------------------------------------------------------

code snippet:

------------------------------------------------------------------------------------------------------------------------------------

CODE OUTPUT:

------------------------------------------------------------------------------------------------------------------------------------

I hope this would help you out

If you have any doubt, you can provide comment /feedback below the answer

Thanks

Add a comment
Know the answer?
Add Answer to:
An Amish farmer has determined that the number of cows he owns will double every year....
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
  • public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which...

    public static double[] getVolumes(double[] base, double[] height, double[] length) Write a Java program called TriangularPrisms which does the following: In the main method: Use a for loop which repeats three times. Within the loop, a. prompt the user to enter the base of the triangular prism and store the value in a double array called base b. prompt the user to enter the corresponding height and store the value in a double array called height c. prompt the user to...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Hi. Could you help me write the below program? Please don't use any header other than...

    Hi. Could you help me write the below program? Please don't use any header other than iostream, no Chegg class, no argc/argv. Nothing too advanced. Thank you! For this assignment you are implement a program that can be used to compute the variance and standard deviation of a set of values. In addition your solution should use the functions specified below that you must also implement. These functions should be used wherever appropriate in your solution. With the exception of...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Problem overview. There are a number of ways to normalize, or scale, a set of values....

    Problem overview. There are a number of ways to normalize, or scale, a set of values. One common normalization technique scales the values so that the minimum value goes to 0, the maximum value goes to 1, and the other values are scaled accordingly. Using this normalization technique, the values of the array below are normalized. Original Array Values -1 -2 2 Normalized Array Values 0.25 0.01.0 0.5 The equation that computes the normalized value from a value xe in...

  • Instructions Write a program called stocks.cpp. The program should prompt the user for the number of...

    Instructions Write a program called stocks.cpp. The program should prompt the user for the number of shares purchased, purchase price per share, the commission for the purchase, sale commission paid, and the price the shares were sold at. The program should validate each of these values to ensure they are acceptable (none of these values can be less than zero) and should then pass them to a function called calculateProfit. The function should use the following formula to determine the...

  • Write a program in Python that computes the interest accrued on an account. You can modify...

    Write a program in Python that computes the interest accrued on an account. You can modify the “futval.py” program given in Chapter 2 to accomplish it. Your program should use a counted loop rather than a formula. It should prompt the user to enter the principal amount, the yearly interest rate as a decimal number, the number of compounding periods in a year, and the duration. It should display the principal value at the end of the duration. To compute...

  • Write a program that will loop ten times. In each iteration prompt user to enter an...

    Write a program that will loop ten times. In each iteration prompt user to enter an integer between -50&50. Print the input, keep a running sum of the inputs, and track the minimun and maximum numbers input. After the loop is complete, minimum number entered, maximum number entered, sum of all numberes entered, and average of all numbers entered. Format all output. Before running the loop, print the label "Input values: ". Within the loop, print value entered by user...

  • A perfect number is a positive integer that is equal to the sum of its (proper)...

    A perfect number is a positive integer that is equal to the sum of its (proper) positive divisors, including 1 but excluding itself. A divisor of a number is one which divides the number evenly (i.e., without a remainder). For example, consider number 6. Its divisors are 1, 2, 3, and 6. Since we do not include number itself, we only have 1, 2, and 3. Because the sum of these divisors of 6 is 6, i.e., 1 + 2...

  • Problem: Create a program that contains two functions: main and a void function to read data...

    Problem: Create a program that contains two functions: main and a void function to read data from a file and process it. Your main function should prompt the user to enter the name of the file (Lab7.txt), store this name, and then call the function sending the name of the file to the function. After the function has completed, the main function should output the total number of values in the file, how many of the values were odd, how...

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