when i enter 10 and 20 i should get a cut of 2.11 and max volume of 192.45...do u know what im doing wrong?
code:
//Yair Jimenez
#include <iostream>
using namespace std;
int main()
{
int length=0,width=0,cut; //givin value to different variables
double volume=0,maxvolume=0,height=0,maxheight=0;
char again = 'y';
while (again=='y'||again=='Y') // allows the user to run the program multiple times
{
cout << "\nEnter the Length: "<<endl; //tells the user to enter the length
cin >> length;
while (length <=0)
{
cout << "\nError,invalid entry.Re-Enter length (must be positive integer): "<<endl; //Displays error message if the width is not a postive integer
cin.clear();
fflush(stdin);
cout << "\nEnter length"<<endl;
cin>>length; //holds the integer entered for length
}
cout <<"\nEnter width: "<<endl;
cin >> width; //holds the integer entered for width
while(width <=0)
{
cout <<"\nError, invalid entry .Re-Enter Length (must be positive integer): "<<endl; //Displays error message if the width is not a postive integer
cin.clear();
fflush(stdin);
cout <<"\nEnter width: "<<endl;
cin >> width;
}
for (height=0;height<(length/2);height+=0.001)
{
volume = (length-(2*height)) * (width-(2 * height)) * (height); //once all integers have been entered it finds the volume using this equation
if (maxvolume < volume) //if maxvolume is less than volume than maxvolume is equal to volume
maxvolume=volume;
cut=height;
}
cout <<"\n For the entered sides of length "<<length<<" and width of "<<width<<endl; //displays information
cout <<"\nResult of maximum volume is: "<<maxvolume<<",and the cut is: "<<cut<<endl;
fflush(stdin);
cout<<endl<<" Do you want to run the program again <y/n>?"<<endl; //ask user if they would like to run the program again
cin>>again;
}
return 0;
}