Click here to Skip to main content
15,891,888 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Comments
AnvilRanger 27-Sep-15 17:50pm    
You have not asked for any help at all. It appears all you did way copy the text of an assignment. You have shown no code, in fact you have show no effort at all so of course we are going to assume this is homework.

We do not do your homework !
It is set for a reason: It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Advice:
- read language documentation.
- Follow tutorials
- Google is your friend.
 
Share this answer
 
Comments
Member 12015191 27-Sep-15 17:07pm    
I didn't ask for anyone to do my homework. I know that i'm supposed to incorporate loop and if else statements but I'm having trouble. Thanks for your help anyways!
Make a top-down approach to design your app in pseudo-code. Conversion into your language of choice is left as exercise.
function app()
{
   forever
   {
      a = read_number
      b = read_number
      c = read_action
      if (c == end) break
      if (c == add) write(a "+" b "=" a+b)
      if (c == sub) write(a "-" b "=" a-b)
      if (c == mul) write(a "*" b "=" a*b)
      if (c == div) write(a "/" b "=" a/b)
   }
}
Regards
Andi
 
Share this answer
 
v2
Comments
Member 12015191 27-Sep-15 17:15pm    
What should 'forever' and 'function' be defined as?
Andreas Gieriet 27-Sep-15 18:23pm    
I suggest you read the text book first to understand the assignment.
This is pseudo code - not C nor C++ nor Java nor any other programming language.
This code should help to express the stated problem in a more formal way than prose.
The "function" is intended to be a function definition...
"forever" means that the loop turns forever...
I don't like to say this, but if you already struggle with these terms, I doubt that you have a chance to implement "read_number" or "read_action"...
I thought that these are obvious terms if you have the faintest idea of any programming language. Otherwise google what a function is and what a forever-loop in C++ is (e.g. C++ forever, or C++ read number, etc.).
Regards
Andi

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900