Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

language : C++ Please create a Math Calculator Program as follows: 1. Display a

ID: 3699495 • Letter: L

Question

language : C++

Please create a Math Calculator Program as follows: 1. Display a Menu of Arithmetic Functions to the user, allowing them to choose Summation, Factorial, Exponential, or Exit the Program. 2. Prompt for and input the user choice of Arithmetic Function. 3. Eexecute the code to input user's positive number, then perform the selected math function. Display those results. 4. Redisplay the main menu. Continue in this fashion until the user enters option 4. Then gracefully stop the program. Validate menu option input and math function integer input appropriately

Explanation / Answer

#include<iostream>
using namespace std;
int main()
{
int choice,num,summation=0,fact=1,base,exponent,value=1;
do{
cout<<endl<<"Welcome to Maths Calculator!"<<endl;
cout<<"1. Summation"<<endl;
cout<<"2. Factorial"<<endl;
cout<<"3. Exponential"<<endl;
cout<<"4. Exit"<<endl;
cout<<"Enter Your Choice :";
cin>>choice;
switch(choice){
case 1:
while(1) {
cout<<"Enter the number till when summation is required :";
cin>>num;
if(num > 0)
break;
}
for(int i=0;i<=num;i++)
summation = summation + i;
cout<<"Summation of first "<<num<<" numbers is: "<<summation<<endl;
break;
case 2:
while(1){
cout<<"Enter the number whose factorial is to be calculated :";
cin>>num;
if(num>-1)
break;
}
if(num==1||num==0)
{
cout<<"Factorial of "<<num<<" is :1"<<endl;
break;
}
else {
for(int i=1;i<=num;i++)
fact = fact * i;
}
cout<<"Factorial of "<<num<<" is :"<<fact<<endl;
break;
case 3:
cout<<"Enter the base and exponent :";
cin>>base>>exponent;
for(int i=1;i<=exponent;i++){
value=value * base;
}
cout<<"Value after calculation is :"<<value<<endl;
break;
case 4:
cout<<"Goodbye!";
break;
default:
cout<<"Wrong Choice! "<<endl;
}
value = 1; //reseting the values
fact = 1;
summation = 0;
if(choice == 4)
break;
} while(1);
}