Question

In: Computer Science

I am unsure as to why I cannot solve my Computer Science question I was just...

I am unsure as to why I cannot solve my Computer Science question I was just wondering if someone could show me exactly what they would do the code is in C++:

write a program that display the following manual for user to chose among calculations

Please select one of the following:

  1. addition
  2. subtraction
  3. multiplication
  4. division
  5. exit

The program will then read in the user entry.

when the user chose "1", it will ask the user "Please enter two numbers separated by space:", read these two numbers into variables, add them and display the sum; when the user chose "2", it will ask the user "Please enter two numbers separated by space:", read these two numbers into variables, subtract the 2nd number from the first one and display the result; when the user chose "3", it will ask the user "Please enter two numbers separated by space:", read these two numbers into variables, multiply them and display the product; when the user chose "4", it will ask the user "Please enter two numbers separated by space:", read these two numbers into variables, divide the first number by the 2nd number, and display the quotient; when the user chose "5", exit the program; when what the user entered is not within the range of 1~5, display "This is Not a valid choice."

Solutions

Expert Solution

please go through screenshots for better understanding. Any doubts comment below.Thank you.

C++ CODE:

#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
   int n, a, b; //intitializing varianles.
   float div;
   cout<<"1.addition\n2.subtraction\n3.multiplication\n4.division\n5.exit\n"; // Display user to enter option
   cin>>n; // Taking option from user
   switch(n)
   {
   case 1:
   {
       cout<<"Enter two numbers sepreated by space:" ; // Ask user to enter space seprated numbers
       cin>>a; // Taking first number
       cin>>b; // Taking second number
       cout<<"sum of two numbers:" <<(a+b) ; // printing addition of two numbers
       break;
   }
   case 2:
   {
       cout<<" enter two number sepreated by space:" ; // Ask user to enter space seprated numbers
       cin>>a; //Taking first number
       cin>>b;// Taking second number
       cout<<"Subtraction of two numbers:" <<(a-b) ;// printing subtraction of two numbers
       break;
   }

   case 3:
   {
       cout<<" enter two number sepreated by space:" ; // Ask user to enter space seprated numbers
       cin>>a; //Taking first number
       cin>>b;// Taking second number
       cout<<"multiplication of two numbers:"<<(a*b) ; //printing multiplication of two numbers
       break;
   }

   case 4:
   {
       cout<<" enter two number sepreated by space:" ; // Ask user to enter space seprated numbers
       cin>>a;//Taking first number
       cin>>b;// Taking second number
       div=a/b; // calculating division
       cout<<"division of two numbers:"<<div ; //printing division of two numbers
       break;
   }
   case 5:
   {
       exit(0); // exit from program
       break;
   }
   default:
   {
       cout<<"this is not a valid choice" ;
       break;
   }

   }
   return 0;
}

We were unable to transcribe this image

cin>>b; // Taking second number cout<<"multiplication of two numbers:"<< (a*b); //printing multiplication of two numbers break; case 4: cout<<" enter two number sepreated by space:"; // Ask user to enter space seprated numbers cin>>a; //Taking first number cin>>b;// Taking second number div=a/b; // calculating division cout<<"division of two numbers:"<<div ; //printing division of two numbers break; case 5: exit(0); // exit from program break; default: cout<<"this is not a valid choice" ; break; return 0;

-ox C:\Program Files (x86)\Dev-Cpp ConsolePauser.exe 1. addition 2. subtraction 3.multiplication 4.division 5.exit Enter two numbers sepreated by space:9 5 sum of two numbers:14 Process exited normally. Press any key to continue ...

- O X C:\Program Files (x86)\Dev-Cpp ConsolePauser.exe 1. addition 2. subtraction 3.multiplication 4.division 5.exit enter two number sepreated by space:9 5 Subtraction of two numbers:4 Process exited normally. Press any key to continue ...

- O X C:\Program Files (x86)\Dev-Cpp ConsolePauser.exe 1. addition 2. subtraction 3.multiplication 4.division 5.exit enter two number sepreated by space:9 5 multiplication of two numbers:45 Process exited normally. Press any key to continue ...

We were unable to transcribe this image

We were unable to transcribe this image


Related Solutions

I am working on a project for my Computer Science course. I am trying to create...
I am working on a project for my Computer Science course. I am trying to create a Battleship game where a user names two coordinates on a grid and is then told whether this results in a "Hit" or a "Miss". Once the ship has been hit a certain number of times (based on the size of the ship) the ship is sunk. I have written all the code but it now fails to execute when I try to run...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
Hello, I am working on an assignment but I am unsure of how to solve it....
Hello, I am working on an assignment but I am unsure of how to solve it. Please help me. The assignment details are below. Consider this scenario: Your friend starts a website, nothingbutflags.com, which is not making money. Your friend asks you to help generate more traffic. You ask your friend how much traffic the website had last month? And your friend replies and says only 500 visits. You also ask how many flags did you sell? Your friend replies...
***** PLEASE solve using MATHCAD, I am unsure on how to solve properly with this application....
***** PLEASE solve using MATHCAD, I am unsure on how to solve properly with this application. Thank you so much! Problem 7: Design a Silicon diode that has a breakdown voltage =20V and has a junction capacitance of 1 pF at no biasing.
Cannot figure out why my c++ program keeps crashing, I am attempting to have the user...
Cannot figure out why my c++ program keeps crashing, I am attempting to have the user decide the size of a 2d array then fill said array. #include <iostream> using namespace std; typedef int* IntArrayPtr; int main(void) { int column, row, i, j; IntArrayPtr *arr_num = new IntArrayPtr[row]; cout << " " << endl << " This program creates a 2D array of dynamic memory, fills it with user entered numbers, " << endl << " Then prints the array...
I am trying to create a classified balance sheet and I am unsure what is involved...
I am trying to create a classified balance sheet and I am unsure what is involved when reporting the current assets, liabilities and owners equity?
*** Please solve Problem 3 using MATHCAD I am unsure how to properly use MATHCAD so...
*** Please solve Problem 3 using MATHCAD I am unsure how to properly use MATHCAD so this would be a tremendous help. Thank you 1. A Si diode doped with ND=2x1016 cm-3 and NA=2x1017 cm-3. The area of the diode is 5m x5 m. If the voltage across the diode is zero: a) Calculate the majority and minority carrier concentrations for the n-side, nn0 and pn0. b) Calculate the majority and minority carrier concentrations for the p-side, pp0 and np0....
This is the first question and I know how to solve this one, but I am...
This is the first question and I know how to solve this one, but I am confused by the second one (The admissions office of a small, selective liberal-arts college will only offer admission to applicants who have a certain mix of accomplishments, including a combined SAT score of 1,300 or more. Based on past records, the head of admissions feels that the probability is 0.58 that an admitted applicant will come to the college. If 500 applicants are admitted,...
Needs to be coded in Python. Hello i am working on a project for my computer...
Needs to be coded in Python. Hello i am working on a project for my computer programming course and i am having trouble with one part. The code needs to be able to produce two versions of an output given inputs by the user. for instance. Here is the code i have to produce the following output. The input from the user are num1 num2 and asc which is just asking if they want the output to be ascending or...
This is my presentation/ research topic, Professionals conduct in Computer Science. I have to give a...
This is my presentation/ research topic, Professionals conduct in Computer Science. I have to give a 10 minutes presentation about it but I dont understand this topic and really dont know what to talk about to make it interesting for the class. I have to talk about what are the problems, questions, my assumption, point of view, and conclusion about the topic, which I am very confused. Im really scared of doing public speaking buy will try my best.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT