Question
1. The Math Program (this is the title you want your void function to display) 1. Add 2. Multiply 3. Exit Here is my code
1.
The Math Program (this is the title you want your void function to display)
1. Add
2. Multiply
3. Exit
Here is my code :
using namespace std; // Function declarations double addition(double num1, double num2); double multiplication(double num1, double num2);
int main() { // Declaring variables int choice; double sum, multiply, product; double num1, num2;
// This loop continues to run until the user enters choice 3 while (true) { // Displaying the menu cout << " Menu" << endl; cout << "----" << endl; cout << "1. Add" << endl; cout << "2. Multiply" << endl; cout << "3. Exit" << endl; cout << "Enter choice :"; cin >> choice;
switch (choice) { case 1: {
cout << "Enter first number :"; cin >> num1; cout << "Enter second number :"; cin >> num2;
sum = addition(num1, num2);
// Displaying the sum of two numbers cout << "The sum of " << num1 << " and " << num2 << " is " << sum << endl; continue; } case 2: { // Getting the inputs numbers entered by the user cout << "Enter first number :"; cin >> num1; cout << "Enter second number :"; cin >> num2; product = multiplication(num1, num2);
// Displaying the product of two numbers cout << "The Product of " << num1 << " and " << num2 << " is " << product << endl; continue; } case 3: { cout << ":: Program Exit ::" << endl; break; } default: { cout << "Invalid input.Must be either 1 or 2 or 3" << endl;
continue; } } break; }
return 0; }
// Function implementation which add two numbers double addition(double num1, double num2) { return num1 + num2; } // Function implementation which multiplies two numbers double multiplication(double num1, double num2) { return num1 * num2; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started