Answer to Question #189156 in C++ for Skye Jordan

Question #189156

Based on Control Structure Selection and Control Structure Looping, answer the following questions:


Write a program that is able to compute some operations on an integer. The program writes the value of the integer and writes the following menu :

1. Add 1

2. Multiply by 2

3. Subtract 4

4. Quit



1
Expert's answer
2021-05-04T16:06:41-0400
#include <iostream>
using namespace std;
int main(){
    int n, choice;
    cout<<"Enter an integer: ";
    cin>>n;
    cout<<n<<endl;
    bool flag = true;
    do{
        cout<<"\n1. Add 1\n2. Multiply by 2\n3. Subtract 4\n4. Quit\n";
        cin>>choice;
        switch(choice){
            case 1: cout<<n + 1; break;
            case 2: cout<<n * 2; break;
            case 3: cout<<n - 4; break;
            case 4: flag = false; break;
            default: cout<<"Invalid choice\n";
        }
    }while(flag);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS