Answer to Question #221199 in C++ for Rosie

Question #221199
Write a program that calculates different kinds of mathematical results based on the user’s menu selection. Ask a user to enter a number from 1 to 30. Establish an error trap to ensure that the number is in the indicated range. Display the following menu: 1. Calculate whether your entry is odd or even. 2. Calculate the cube of your entry. 3. Calculate a circle’s area using your entry as radius. Ask the user for his/her choice from the menu. Using a SWITCH statement (with an appropriate default), display the correct result from the user’s menu choice. Your program must calculate the correct response to each menu option.
1
Expert's answer
2021-07-29T03:06:30-0400
#include <iostream>
using namespace std;
int main()
{
    int number;
    cout<<"Enter the number. The number must be between 1 and 30\n";
    cin>>number;
    if(number < 1 || number >30 ){
        cout<<"Enter a number between 1 and 30\n";
        main();
    }
    int n;
    cout<<"Enter the operation you want to perform from the menu. Enter 1 or 2 or 3\n";
    cout<<" 1. Calculate whether the number is odd or even. \n";
    cout<<" 2. Cube the number. \n";
    cout<<"3. Calculate an area of  circle using the number as radius\n";
    
    
    cin>>n;
    switch(n){
        case 1: 
        if(number % 2== 0) 
        {
            cout<<"The entry is even\n";
            
        } 
        else{
            cout<<"The entry is odd \n";
            
        }
        break;
        case 2: cout<<"The area of the cube is \t"<<number * number * number<<endl;
        break;
        case 3: cout<<"The of the circle is \t"<< 3.142 * number * number <<endl;
        break;
        default:
         cout<<"The number is valid\n";
    }
    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
New on Blog
APPROVED BY CLIENTS