Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with having the result as 1 decimal. C++ Ron bought several acres of farm to grow and sell vegetables. Suppose that Ron wants

Need help with having the result as 1 decimal.

C++

Ron bought several acres of farm to grow and sell vegetables. Suppose that Ron wants to grow a maximum of two types of vegetables.

Write a program that prompts Ron or the user to do the following:

Enter the total farm area in acres.

The number of vegetables (one or two) that the user wants to grow.

If the user wants to grow two types of vegetables, then prompt the user to enter the portion (as a percentage) of land used for the first vegetable.

Enter the seed cost, plantation cost, fertilizing cost, labor cost, and selling price per acre.

If the user specified 2 vegetables, prompt the user to enter the items in step 4 for the second vegetable.

The program then outputs

The total revenue.

The profit/loss.

My Code:

#include

using namespace std;

int main() {

double acres;

int vegetables;

double portion;

double seed, plantation, fertilizing, labor, selling;

double seed2, plantation2, fertilizing2, labor2, selling2;

double revenue1, revenue2, totalrevenue, cost1, cost2, totalcost1, totalcost2, totalcost;

cout << "Enter the total farm area in acres: ";

cin >> acres;

cout << "How many vegetables 1 or 2: ";

cin >> vegetables;

if (vegetables == 2) {

cout << "What portion of the land, as a percentage: ";

cin >> portion;

}

cout << "Enter seed cost: ";

cin >> seed;

cout << "Enter plantation cost: ";

cin >> plantation;

cout << "Enter fertilizing cost: ";

cin >> fertilizing;

cout << "Enter labor cost: ";

cin >> labor;

cout << "Enter selling price per acre: ";

cin >> selling;

if (vegetables == 2) {

cout << "Enter seed cost for vegetable 2: ";

cin >> seed2;

cout << "Enter plantation cost for vegetable 2: ";

cin >> plantation2;

cout << "Enter fertilizing cost for vegetable 2: ";

cin >> fertilizing2;

cout << "Enter labor cost for vegetable 2: ";

cin >> labor2;

cout << "Enter selling price per acre for vegetable 2: ";

cin >> selling2;

}

if (vegetables == 2) {

revenue1 = ((portion * acres) / 100) * selling;

revenue2 = (((100 - portion) * acres) / 100) * selling2;

totalrevenue = revenue1 + revenue2;

} else {

revenue1 = acres * selling;

totalrevenue = revenue1;

}

cout << "The total revenue: " << fixed;

cout << setprecision(1) << totalrevenue << endl;

if (vegetables == 2) {

cost1 = (seed + plantation + fertilizing + labor) * ((portion * acres) / 100);

totalcost1 = revenue1 - cost1;

cost2 = (seed2 + plantation2 + fertilizing2 + labor2) * (((100 - portion) * acres) / 100);

totalcost2 = revenue2 - cost2;

totalcost = totalcost1 + totalcost2;

} else {

cost1 = seed + plantation + fertilizing + labor + selling;

totalcost1 = revenue1 - cost1;

totalcost = totalcost1;

}

cout << "The profit/loss: " << fixed;

cout << setprecision(1) << totalcost << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions