Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ToolsArchitecture Test Analyce Window Hep dit View Project Build DebugTeam Attac

ID: 3700288 • Letter: T

Question

ToolsArchitecture Test Analyce Window Hep dit View Project Build DebugTeam Attach. S120 Queß.cpp s X Miscellaneous Files (Global Scope ?,- " Quiz8: Use functions to perfors different operations on two user-entered integers Program should end upon user's command Request and perform the chosen operation repeatedly Stop only when user has decided to exit #included°strean) using namespace std; 10 11 13 I global variables 14 int numl, nun2; int main() 16 17 18 19 // declare needed variables int choice // display message for the program cout

Explanation / Answer

#include <iostream>

using namespace std;

//global variables num1,num2

int num1,num2;

int main(){

int choice = 0;

do{

cout << " This program should perform some chosen operations on two integers ";

cout << "User should enter the integers and choice what operation to perform ";

//Displaying operations

cout << " 1.Addition ";

cout << " 2.Subtraction ";

cout << " 3.Multiplication ";

cout << " 4.Division ";

cout << " 5.Mod ";

cout << " -1.Exit ";

cout <<" Enter your choice :";

cin >> choice;

//taking input numbers

if(choice != -1){

cout <<" Enter first number :";

cin >> num1;

cout <<" Enter second number :";

cin >> num2;

}

//validate if second number is zero when choice is divsion

if(choice == 4){

if(num2 == 0){

cout << " Invalid number "<< num2;

cout << " Enter second number :";

cin >> num2;

}

}

//Displaying result

switch(choice){

case 1:

cout << " Addtion of " << num1 << " and " << num2 << " is " << num1+num2 <<endl;

break;

case 2:

cout << " Subtraction of " << num1 << " and " << num2 << " is " << num1-num2 <<endl;

break;

case 3:

cout << " Multiplication of " << num1 << " and " << num2 << " is " << num1*num2 <<endl;

break;

case 4:

cout << " Division of " << num1 << " and " << num2 << " is " << num1/num2 <<endl;

break;

case 5:

cout << " Mod of " << num1 << " and " << num2 << " is " << num1%num2 <<endl;

break;

case -1:

break;

default:

cout << "invalid choice ";

}

}while(choice!=-1);

return 0;

}