Answer to Question #326625 in Algorithms for Koke

Question #326625

(While loop structure)

Write a small program that displays a menu with the following options:


   A program that will calculate either the diameter, circumference, or area of a circle. Select your choice.

  1. Diameter
  2. Circumference
  3. Area 
  4. Quit

Use the switch statement. The program is to ask for the radius of a circle. Present the menu and execute the corresponding calculation.



1
Expert's answer
2022-04-10T12:36:33-0400


#include <iostream>


using namespace std;


int main(){
	int ch =0;
	const double PI = 3.14159;
	while(ch!=4){
		cout<<"1. Diameter\n";
		cout<<"2. Circumference\n";
		cout<<"3. Area\n";
		cout<<"4. Quit\n";
		cout<<"Your choice: ";
		cin>>ch;
		float r;
		if(ch>=1 && ch<=3){
			cout<<"Enter the radius of a circle: ";
			cin>>r;
		}
		switch(ch){
		case 1:
			cout<<"Diameter: "<<(r*2)<<"\n\n";
			break;
		case 2:
			cout<<"Circumference: "<<(2*PI*r)<<"\n\n";
			break;
		case 3:
			cout<<"Area: "<<(PI*r*r)<<"\n\n";
			break;
		case 4:
			break;
		default:
			break;
		}


	}
	system("pause");
	return 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
APPROVED BY CLIENTS