Can somebody help me do the math for this program (plz no Calculus, dont understand it)

0 votes
asked Mar 3 by anonymous

/*

Write a program that prompts the user to enter the following:

The width of the river

The distance of the factory downstream on the other side of the river

The cost of laying the power line under water

The cost of laying the power line over land

The program then outputs the length of the power line that should run under water and the length that should run over land so the cost of constructing the power line is at the minimum. The program should also output the total cost of constructing the power line.

*/

#include <iostream>

#include <iomanip>

#include <cctype>

#include <cmath>

using namespace std;

double CostFunc(double x, double y, double w, double z);

int main()

{

double rWidth, dFactory;

double powCostWater, powCostLand;

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

cout << "Enter the width of the river: ";

cin >> rWidth;

cout << endl << "Enter the factory's distance from the river: ";

cin >> dFactory;

cout << endl << "The cost for running power on land: ";

cin >> powCostWater;

cout << endl << "The cost for running power underwater: ";

cin >> powCostLand;

if (rWidth > 0 && dFactory > 0 && powCostWater > 0 && powCostLand > 0)

CostFunc(powCostWater,powCostLand,rWidth,dFactory);

else cout << "Input values greater then Zero!!!";

return 0;

}

double CostFunc(double x, double y, double w, double z)

{

double totalPrice = 5280*w*x + 5280 *z*y;

double minCost = totalPrice;

while(minCost >= totalPrice)

{

z -= 0.01;

w += 0.01;

minCost = 5280*w*x + 5280*z*y;

}

cout << "The minimum price is $" << minCost;

cout << endl << "The length underwater: " << w;

cout << endl << "The length on land: " << z;

return 0;

}

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...