Question
Add an additional calculation to the calculator. This calculation should sum all of the integers between the two numbers the user entered (truncating the numbers
Add an additional calculation to the calculator. This calculation should sum all of the integers between the two numbers the user entered (truncating the numbers if the user entered a decimal). For example, if the user entered 5.2 and 8.7 then the calculator should sum all of the values between 5 and 8 (i.e. 5 + 6 + 7 + 8). Remember that if you store a double value in an int variable it is automatically truncated.
#include
using namespace std;
int main() {
// your code goes here
double operend1;
double operend2;
int operation;
cout <<" ";
cout<<"welcome to the simple calculator program. ";
cout<< "Enter the two real value and then select the mathematical operation apply to them. ";
while(true){
cout<<"Enter the first value : ";
cin>>operend1;
cout<<"Enter the second value : ";
cin>>operend2;
cout<<"Enter the operation(1-add, 2-subtract, 3-multiply, 4-divide, 5 - for sum of all integer between two given numbers) : ";
cin>>operation;
if(operation<1 || operation>5){
cout<<"Invalid operation";
continue;
}
switch(operation){
case 1 : cout< cout<<" "; break; case 2 : cout< cout<<" "; break; case 3 : cout< cout<<" "; break; case 4 : cout< cout<<" "; break; case 5 : int sum=0; for(int i=operend1; i<=operend2; i++) sum+=i; cout< cout<<" "; } int n; cout<<"do u want to continue? enter 0 to no and 1 for yes : "; cin>>n; if(n==1) continue; else break; } return 0; }
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