In: Computer Science
Compute the area under y = √x between x = a and x = b where a and b are user specified values obtained via cin. Account for invalid user input cases of a < 0 and a > b. For each case of invalid input, immediately output to the user what the error was. Allow the user a total of three chances to enter valid input for each input request. If the user enters incorrect input three times in a row for an input request, display a different error and exit the program.
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{
float a,b;
for(int i=0;i<3;i++)
{
cout<<"Enter a and b"<
if(a>=0&&a<=b)
break;
else
{
if(i==2)
{
cout<<"You have exhausted all 3 chances"<
}
cout<<"Invalid values entered"<
}
float b3=b*b*b,a3=a*a*a;
float value=(float)(sqrt((b3))-sqrt(a3));
cout<<"The area computed is equal to :
"<<(float)((float)2/(float)3)*(float)value<
}