Answer to Question #203682 in C++ for Khojo

Question #203682

A program needs to be developed for helping your younger siblings to calculate the area of a square when the input(side) is given. The program first of all needs to permit him/her to work on the area when he/she is below class 6. The program should allow for new entering of class when the class given doesn’t meet the requirement for working on area of a square. Also, ensure that the side given is a positive number else allow him/her enter a new side. 


1
Expert's answer
2021-06-05T23:53:17-0400
#include<iostream>
using namespace std;
//Function to get area of a square
double  area_square(double side){
	return side * side;
}


int main(){
	int class_entered;
	double side;
	cout<<"Enter your class"<<endl;
	cin>>class_entered;
	if(class_entered<6){
		cout<<"Enter the side of the square"<<endl;
		cin>> side;
		if(side>0){
			cout<<"The area of the square is: \t"<<area_square(side)<<endl;
		}
		else{
			cout<<"The side must be a positive number.\t Kindly enter a positive number"<<endl;
			main();
		}
	}
	else{
		cout<<"The class must be below class 6.\t Enter a class below class six to get area of the square"<<endl;
		main();
	}
	cout<<"Click 1 if you want to continue or 2 terminate the program \n";
	int x ;
	cin>>x;
	if(x==1){
		main();
	}
	else{
		exit(0);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog