Create a script to input 2 numbers from the user. The script will then ask the user to perform a numerical calculation of addition, subtraction, multiplication, or division. Once the calculation is performed, the script will end.

Respuesta :

Answer:

The code given is written in C++

First we declare the variables to be used during the execution. The names given are self-explanatory.

Then the program outputs a request on the screen and waits for user input, for both numbers and one more time for the math operation wanted, selected with numbers 1 to 4.

Finally, the program executes the operation selected and outputs the result on screen.  

Code:

#include <iostream>

int main()

{

// variable declaration

float numberA;

float numberB;

int operation;

float result=0;

//number request

std::cout<<"Type first number:\n"; std::cin>>numberA;

std::cout<<"Type second number:\n"; std::cin>>numberB;

 

//Operation selection

cout << "Select an operation\n";

cout << "(1) Addition\n";

cout << "(2) Subtraction\n";

cout << "(3) Multiplication\n";

cout << "(4) Division\n";

std::cout<<"Operation:\n"; std::cin>>operation;

switch(operation){

 case 1:

  result = numberA+numberB;

  break;

 case 2:

  result = numberA-numberB;

  break;

 case 3:

  result = numberA*numberB;

  break;

 case 4:

  result = numberA/numberB;

  break;    

 default:

  std::cout<<"Incorrect option\n";

 }

//Show result

std::cout<<"Result is:"<<result<<::std::endl;

return 0;

}