Question

using Microsoft Visual Studio C++ write a compute program that will allow the user to: 1.Get...

using Microsoft Visual Studio C++ write a compute program that will allow the user to:

1.Get a Factorial (using a loop)
2. perform addition and subtraction
3.allow the user to quit the program
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;

int main() {
   int x;
   cout << "1. Factorial\n";
   cout << "2. Addition And Subtraction\n";
   cout << "3. Quit\n";
   cout << "Enter your choice: ";
   cin >> x;
      
       switch (x)
       {
       case 1:
       {
           int i, n, factorial = 1;

           cout << "Enter a positive integer: ";
           cin >> n;

           for (i = 1; i <= n; ++i) {
               factorial *= i; // factorial = factorial * i;
           }
           cout << "Factorial of " << n << " = " << factorial;
       }
           break;
      
       case 2:
       {
           char o;
           float num1, num2;

           cout << "Enter an operator (+, -): ";
           cin >> o;

           cout << "Enter two operands: ";
           cin >> num1 >> num2;

           switch (o)
           {
           case '+':
               cout << num1 << " + " << num2 << " = " << num1 + num2;
               break;
           case '-':
               cout << num1 << " - " << num2 << " = " << num1 - num2;
               break;
           default:
               cout << "Error! operator is not correct";
               break;
           }
       }
           break;
       case 3:
       {
           exit;
       }
           break;
      
       default:
           cout<<"Choice other than 1, 2 and 3";
           break;
       }
       return 0;
}

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)

Add a comment
Know the answer?
Add Answer to:
using Microsoft Visual Studio C++ write a compute program that will allow the user to: 1.Get...
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
ADVERTISEMENT