Question: Something about my math for the profits is wrong. the first if function for only one vegetable type puts out the correct revenue but not

Something about my math for the profits is wrong. the first if function for only one vegetable type puts out the correct revenue but not the profit needed need. But the else part for when 2 vegetable types are given only the revenue gives the correct answers and the profits are off.

couple inputs and needed outcomes are as follows: 1st inputs - 100 2 1 1 1 1 1 1 1 2 1 2 1 ; answers needed - revenue = 100.0, profit/loss = -498.0

1st inputs - 150 2 40 2 3 5 30 36 0.5 2 5 29 40 ; answers needed - revenue = 5760.0, profit/loss = 75.0

#include

#include

#include

using namespace std;

int main() {

//************************

// Many declared variables

//************************

double FarmArea;

int NumVegType;

double SeedCostOne;

double PlantCostOne;

double FertCostOne;

double LaborCostOne;

double AcreSellPriceOne;

double FarmAreaOne;

double TotalOne;

double SeedCostTwo;

double PlantCostTwo;

double FertCostTwo;

double LaborCostTwo;

double AcreSellPriceTwo;

double FarmAreaTwo;

double TotalTwo;

double TotalRev;

double TotalProfit;

cout << fixed << showpoint << setprecision(2);

//****************************************************

// Inputs for farm area, and number of vegetable types

//****************************************************

cout << "Enter the area of the farm" << endl;

cout << "in acres here: ";

cin >> FarmArea;

cout << endl;

cout << "Enter the number of vegetables" << endl;

cout << "types to be grown (one or two): ";

cin >> NumVegType;

cout << endl;

if (NumVegType == 1)

{

cout << "Enter seed cost one here: ";

cin >> SeedCostOne;

cout << endl;

cout << "Enter plantation cost one here: ";

cin >> PlantCostOne;

cout << endl;

cout << "Enter fertilizing cost one here: ";

cin >> FertCostOne;

cout << endl;

cout << "Enter labor cost one here: ";

cin >> LaborCostOne;

cout << endl;

TotalOne = SeedCostOne + PlantCostOne + FertCostOne + LaborCostOne;

cout << "Enter vegetable selling" << endl;

cout << "price per acre one here: ";

cin >> AcreSellPriceOne;

cout << endl;

TotalRev = AcreSellPriceOne * FarmArea;

TotalProfit = TotalRev - (TotalOne * FarmArea);

}

else

{

cout << "Enter first vegetable type" << endl;

cout << "portion of area to be" << endl;

cout << "farmed here: ";

cin >> FarmAreaOne;

cout << endl;

FarmAreaTwo = 100 - FarmAreaOne;

cout << "Enter first seed cost here: ";

cin >> SeedCostOne;

cout << endl;

cout << "Enter first plantation cost here: ";

cin >> PlantCostOne;

cout << endl;

cout << "Enter first fertilizing cost here: ";

cin >> FertCostOne;

cout << endl;

cout << "Enter labor cost for each" << endl;

cout << "acre of the first vegetable: ";

cin >> LaborCostOne;

cout << endl;

TotalOne = SeedCostOne + PlantCostOne + FertCostOne + LaborCostOne;

cout << "Enter first vegetable selling" << endl;

cout << "price per acre here: ";

cin >> AcreSellPriceOne;

cout << endl;

cout << "Enter second seed cost here: ";

cin >> SeedCostTwo;

cout << endl;

cout << "Enter second plantation cost here: ";

cin >> PlantCostTwo;

cout << endl;

cout << "Enter second fertilizing cost here: ";

cin >> FertCostTwo;

cout << endl;

cout << "Enter labor cost for each" << endl;

cout << "acre of the second vegetable: ";

cin >> LaborCostTwo;

cout << endl;

TotalTwo = SeedCostTwo + PlantCostTwo + FertCostTwo + LaborCostTwo;

cout << "Enter second vegetable selling" << endl;

cout << "price per acre here: ";

cin >> AcreSellPriceTwo;

TotalRev = (FarmArea * 0.01 * FarmAreaOne * AcreSellPriceOne) + (FarmArea * 0.01 * FarmAreaTwo * AcreSellPriceTwo);

TotalProfit = TotalRev - (TotalOne + TotalTwo);

}

cout << "Total Revenue is: "

<< TotalRev;

cout << endl;

if (TotalProfit < 0)

{

TotalProfit = -TotalProfit;

cout << "Loss is: "

<< TotalProfit;

cout << endl;

}

else

cout << "Total profit is: "

<< TotalProfit;

cout << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!