![mary9590](/avatars/30658.jpg)
mary9590
09.10.2019 •
Computers and Technology
Write a program which accepts two integers from the user. then it asks the user what he wants to do with those two numbers. if the user choice is
‘a’ – add the two numbers
‘b’ – subtract the second number from the first number
‘c’ – multiply the first number by the second number
‘d’ – divide the first number by the second number
‘q’ – end the operation
your program should continue to accept the two numbers and the user choice unless the user enters ‘q’ as choice.
Solved
Show answers
More tips
- C Computers and Internet IMHO: What is it, why is it important, and how to use it?...
- H Health and Medicine How to Calculate Your Ideal Weight?...
- S Style and Beauty Discover the Art of Nail Design: How Do You Paint Your Nails?...
- P Philosophy How to Develop Extrasensory Abilities?...
- O Other Everything You Need to Know About Kudyabliks...
- C Computers and Internet The Twitter Phenomenon: What it is and How to Use it...
- C Computers and Internet How to Choose a Laptop: Expert Guide and Tips...
- C Computers and Internet How to Choose a Monitor?...
- H Horoscopes, Magic, Divination Where Did Tarot Cards Come From?...
- S Style and Beauty How to Make Your Lips Fuller? Ideas and Tips for Beautiful Lips...
Answers on questions: Computers and Technology
- C Computers and Technology Is it bad to leave external hard drive on for hours...
- C Computers and Technology Does drive stop uploading when pc is asleep...
- C Computers and Technology How do I modify objects in power point 2016 for an assignment...
- C Computers and Technology Consider the bias (b) as a constant that is added to the ANN equation to represent the final value of y when inputs are equal to zero y=f(x1w1 + x2w2 + …+b)...
- H History The major impact of the treaty of Versailles on Germany was the treaty that led to?...
- M Mathematics Write the inequality in words that is equivalent to 3 2...
- M Mathematics Our family road trip to Yellowstone required driving approximately 610 miles. After 4 hours of driving we stopped for lunch and found we had traveled 252 miles. At this rate, how...
- M Mathematics Some pls help to give 20 points...
- H Health What type of activity is being performed in the picture - cardio - strength training - flexibility - cross training...
- E English How is high school for you? Is stressful? Easy?...
Ответ:
// program in C++.
#include <bits/stdc++.h>
using namespace std;
// function to print choice menu
void menu()
{
cout<<"A – Add the two numbers:"<<endl;
cout<<"B – Subtract the second number from the first number:"<<endl;
cout<<"C – Multiply the first number by the second number:"<<endl;
cout<<"D – Divide the first number by the second number:"<<endl;
cout<<"Q – End the operation:"<<endl;
}
// driver function
int main()
{
// variables
int x,y;
char ch;
int flag=1;
do{
cout<<"Enter first number:";
// read first number
cin>>x;
cout<<"Enter second number:";
// read second number
cin>>y;
// call menu function
menu();
cout<<"Enter your choice:";
// read choice
cin>>ch;
switch(ch)
{
case 'A':
case 'a':
cout<<"Addition of two numbers is:"<<(x+y)<<endl;
break;
case 'B':
case 'b':
cout<<"Subtract the second from the first is:"<<(x-y)<<endl;
break;
case 'C':
case 'c':
cout<<"Multiplication of two numbers is:"<<(x*y)<<endl;
break;
case 'D':
case 'd':
cout<<"Division the first by the second is:"<<(x/y)<<endl;
break;
case 'Q':
case 'q':
flag=0;
}
if(flag==0)
break;
}while(ch!='Q'||ch!='q');
return 0;
}
Explanation:
Read two numbers from user.Then read the choice for operation on both the numbers. Then print the choices of operation by calling menu() function.If choice is "A" then print Addition of both.if choice is "B" then print subtraction of second from first number.if choice is "C" then print the multiplication of both numbers.If choice is "D" then print division of first by second.If the choice is "Q" then quit the operation. Repeat this until user's choice is "Q".
Output:
Enter first number:6
Enter second number:2
A – Add the two numbers:
B – Subtract the second number from the first number:
C – Multiply the first number by the second number:
D – Divide the first number by the second number:
Q – End the operation:
Enter your choice:A
Addition of two numbers is:8
Enter first number:8
Enter second number:2
A – Add the two numbers:
B – Subtract the second number from the first number:
C – Multiply the first number by the second number:
D – Divide the first number by the second number:
Q – End the operation:
Enter your choice:Q
Ответ: