Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Having trouble with some HW and dont want the answers, just looking for some ste

ID: 673277 • Letter: H

Question

Having trouble with some HW and dont want the answers, just looking for some step-by-step directions on how one would go about creating the following C++ code.

1. Design a function whose task is to robustly confirm the validity of the user’s input for a dimension (the user’s input will occur in main). When an incorrect value for a dimension has been entered, the function should output a message to those given below and prompt the user to re-enter the dimension. The function should return to the function call a valid value.
“The height of a rectangle must be greater than zero.” (when checking the input for height of a rectangle)
“The radius of a sphere must be greater than zero.” (when checking the input for radius of a sphere)

will rate!

Explanation / Answer

#include<iostream>
using namespace std;

double readHeight(int Validity)
{
double height1;
if(Validity == 0)
{

cout<<"The height of a rectangle must be greater than zero"<<endl;
cout<<"Re-Enter the Height"<<endl;
cin>>height1;
}

return height1;
}

double readRadius(int validity)
{
double radius1;
if(validity == 0)
{

cout<<"The radius of a sphere must be greater than zero"<<endl;
cout<<"Re-Enter Radius"<<endl;
cin>>radius1;
}
return radius1;
}

int main()
{
double height, radius;

int validity1, validity2;
cout<<"Enter Height of An Reactange"<<endl;
cin>>height;
if(height > 0)
{
validity1 = 1;
cout<<"Height of Reactangle is : "<<height<<endl;
}
else
{
cout<<"Height of Reactangle is : "<<readHeight(0)<<endl;
}

cout<<"Enter Radius of sphere"<<endl;
cin>>radius;
if(radius > 0)
{
validity2 = 1;
cout<<"Radius of Sphere is "<<radius<<endl;
}
else
{
cout<<"Height of Reactangle is : "<<readRadius(0)<<endl;
}

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote