Square root in C++ || Cube root in C++ ||switch case || C++ || Turbo C++

In this, we are going to see the topic of Switch case in C++.

This is a program of Switch Case in which we are going to calculate Square-root and Cube-root of a number according to user's choice.

The code given below can be used for TURBO C++ Compiler:-

#include<iostream.h>
#include<conio.h>
#include<math.h>

void main()
{
    clrscr();
    cout << "\n **** This Program is of Switch Case **** \n";
    float number;
    char user_input;
    cout<<"Enter the to calculate the square-root or cube-root\n";
    cin>>number;
    cout<<"Select the operation from the list below\n";
    cout<<"Press 's' for Square-root of the number\n";
    cout<<"Press 'c' for Cube-root of the number\n";
    cin>>user_input;

    switch (user_input)
    {
    case 's':
        float result;
        result = sqrt(number);
        cout<<"The Square-root of "<<number<<" is = "<<result<<endl;
        break;

    case 'c':
        result = cbrt(number);
        cout<<"The Cube-root of "<<number<<" is = "<<result<<endl;
        break;
    
    default:
        cout << "Oops!! Your input is not accepted.\n";
        cout << "Please read the instructions carefully\n";
        break;
    }

    cout << "Thank You";

    getch();
}

   
    

The code given below can be used for g++/gcc Compiler:-

#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    cout << "\n **** This Program is of Switch Case **** \n";
    float number;
    char user_input;
    cout<<"Enter the to calculate the square-root or cube-root\n";
    cin>>number;
    cout<<"Select the operation from the list below\n";
    cout<<"Press 's' for Square-root of the number\n";
    cout<<"Press 'c' for Cube-root of the number\n";
    cin>>user_input;

    switch (user_input)
    {
    case 's':
        float result;
        result = sqrt(number);
        cout<<"The Square-root of "<<number<<" is = "<<result<<endl;
        break;

    case 'c':
        result = cbrt(number);
        cout<<"The Cube-root of "<<number<<" is = "<<result<<endl;
        break;
    
    default:
        cout << "Oops!! Your input is not accepted.\n";
        cout << "Please read the instructions carefully\n";
        break;
    }

    cout << "Thank You";

    return 0;
}

    
    

#ENJOY CODING


1 Comments

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

  1. 👌👌👌😮😮😮

    ReplyDelete

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post