Question

Problem 9: (20 Points) Write a CH program to implement sum, subtraction, multiplication and division operations of two number

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

float sum(float x, float y){

return x+y;

}

float subtract(float x, float y){

return x-y;

}

float multiply(float x, float y){

return x*y;

}

float divide(float x, float y){

return x/y;

}

int main() {

  

  while(true){

   cout << "Enter your choice: " << endl;

   cout << "1. Sum" << endl;

   cout << "2. Subtraction" << endl;

   cout << "3. Multiplication" << endl;

   cout << "4. Division" << endl;

   cout << "0. quit" << endl;

  

   int choice;

float x, y;

   cin >> choice;

   switch(choice){

   case 1:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << sum(x, y) << endl;

   break;

   case 2:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << subtract(x, y) << endl;

   break;

   case 3:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << multiply(x, y) << endl;

   break;

   case 4:

   cout << "Enter 2 nubmers: " << endl;

   cin >> x >> y;

   cout << divide(x, y) << endl;

   break;

   case 0:

   cout << "quit!" << endl;

   return 0;

   }

  }

  return 0;

}

} 8 } } main.cpp saved 1 #include <iostream> 2 using namespace std; 3 4 float sum( float x, float y){ 5 | return x+y; 6 7 flo30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 int choice; float x, y; cin >> cEnter your choice: 1. Sum 2. Subtraction 3. Multiplication 4. Division 0. quit 1 Enter 2 nubmers: 2 4.5 6.5 Enter your choiceEnter your choice: 1. Sum 2. Subtraction 3. Multiplication 4. Division 0. quit 4 Enter 2 nubmers: 2 4 0.5 Enter your choice:

***********************************************************************************************************

Please upvote the answer. It will encourage me to answer more questions and it will be very helpful to me. Thank You.

***********************************************************************************************************

Add a comment
Know the answer?
Add Answer to:
Problem 9: (20 Points) Write a CH program to implement sum, subtraction, multiplication and division operations...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT