In: Computer Science
Hey, Following is the Cpp code for the given question
Please do rate my answer and do revert back if you have any doubts
*************************************************************************************************************************************
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
// Intializing varibales for storing various values
int n = 0,i=1;
char choice;
float dia=0;
// Entering into calculator
cout<<"********** Welcome to The Hemisphere Surface Area /
Volume Calculator **********\n";
// Infinte loop
while (1) {
l1: // Label for getting to starting of the program
cout<< "Enter 1 to Calculate Surface Area of
Hemispheres\n";
cout<< "Enter 2 to Calculate Volume of Hemispheres\n";
cin>> n; // Getting choice from the user
// Calculating area
if(n==1) {
l2:
cout << "How Many Hemispheres’ Surface Areas Would You Like
to Calculate? ";
cin >> n;
// If proper value is not entered
if (n <= 0){
cout << "Number of spheres must be one or more\n";
goto l2; //Ask again
}
else {
// Calculating surface area of each sphere
for(i=1;i<=n;i++) {
l5:
cout << "Enter the diameter of hemisphere "<< i
<< " in meters: ";
cin >> dia;
if (dia < 0) {
cout << "Diameter cannot be negative";
goto l5;
}
cout << "The Surface Area of the Hemisphere with Diameter: "
<< dia << " meters is: "<<
0.25*3.14*(pow(dia,2))<<"\n"; // Surface Area
}
}
}
// Calculating Voulme
else if(n == 2){
l3:
cout << "How many hemispheres’ volumes would you like to
calculate?: ";
cin >> n;
if (n <= 0){
cout << "Number of spheres must be one or more";
goto l2;
} else {
for(i=1;i<=n;i++) {
l6:
cout << "Enter the diameter of hemisphere "<< i
<< " in meters: ";
cin >> dia;
if (dia < 0) {
cout << "Diameter cannot be negative";
goto l6;
}
cout << "The Voulme of the Hemisphere with Diameter: "
<< dia << " meters is: "<<
2*3.14*0.125*(pow(dia,3))<<"\n";
}
}
}
// Go to starting if proper chocie is not entered
else {
goto l1;
}
// Asking user if he wishes to continue
cout << "Would you Like to Run the The Hemisphere Surface
Area / Volume Calculator again?\n";
l4:
cout << "Enter Y or y For YES or N or n For NO: ";
cin >> choice;
cout << "\n";
if (choice == 'Y' || choice == 'y') {
goto l1; // Goto starting of the program
}
else if (choice == 'N' || choice == 'n') {
break; // Break the infinite loop
}
else {
goto l4; // Ask again
}
}
return 0;
}
***********************************************************************************************************************************************
Output of the porgram: