About C/C++ Hub

C/C++ Learners Hub

Super friendly <br/>code & developer communities

Super friendly
code & developer communities

A place for coders and developers to share, learn and grow together.

Back to Hub

Help me also with this question: a farmer wishes to know the cost and the amount of fertilizer required for his rectangular field of crops. The amount of fertilizer is determined by first calculating the area of a field and multiplying that by the rate of fertilizer application per square metre. Given that the rate of application is 0.05kg per square  meter and the cost per kg of fertilizer is $10.50 per kg. Write a program that accept the length and width of a given field from the farmer. The program then calculates and prints the area of the field , the amount of fertilizer required and the total cost of fertilizer in dollars

2      Reply

Here is your C++ program


using namespace std;

int main() {

  float l,w,area,fertilizer_required,cost;

  cout<<"Enter the length of field in meters:";

  cout<<"Enter the width of field in meters:";

  area = l * w;
  cout<<"Area of field in sq. meter: "<<area<<endl;

  fertilizer_required = area * 0.05;
  cout<<"Fertilizer Required in KG: "<<fertilizer_required<<endl;

  cost = fertilizer_required * 10.50;
  cout<<"Cost in $: "<<cost<<endl;

  return 0;

Enter the length of field in meters:10
Enter the width of field in meters:20
Area of field in sq. meter: 200
Fertilizer Required in KG: 10
Cost in $: 105

Thanks for your  help. I really appreciate.