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

You will prompt the user for and read in an integer between 0 and 25, inclusivel

ID: 3669292 • Letter: Y

Question

You will prompt the user for and read in an integer between 0 and 25, inclusively. If the integer is not in range, you will display a meaningful message indicating it is either less than 0 or greater than 25, and then continually re-prompt the user to enter the integer again until the user enters a valid integer.

• Once the user has entered a valid integer, you will then prompt the user for and read in a second integer between –15 and 30, inclusively. If this second integer is not in range, you will display a meaningful message indicating it is either less than –15 or greater than 30, and then continually re-prompt the user to enter the integer again until the user enters a valid integer.

• Once both integers have been entered, you will prompt the user for and read in the arithmetic operation that the user wishes to perform as follows: addition (+), subtraction (–), multiplication (*), division (/), or modulus (%). If the user enters an operation other than those listed, you will display a meaningful message indicating that the operation is invalid, and then exit the program (i.e., not perform the requested operation).

• You will then perform the requested arithmetic operation as input by the user, showing the details of the operation (i.e., the actual operation being performed). Additionally, you will display a meaningful message indicating whether the result of the operation was negative, zero, or positive. • Your code should be well documented in terms of comments. For example, good comments in general consist of a header (with your name, course section, date, and brief description), comments for each variable, and commented blocks of code.

Example of OutPut

Enter an integer between 0 and 25, inclusively: 16 Now enter a second integer between -15 and 30, inclusively: -4 Enter the arithmetic operation (+, -, *, /, or %) you'd like to perform : * Multiplicatin: 16 * -4 = -64 The result of the operation (-64) is negative! mat0299@faculty:~/csce1030S ./a.out mat0299@faculty:/csce1030s ./a.out

Explanation / Answer

#include <iostream>

using namespace std;

void showResult(int reslt);

int main(){
   int num1, num2, result; // num1 and num2 varibale to store integer values to perform arithmetic operation
   char operand;   // character variable to read and store a user selected operand
  
   do{ // loop to promt user to enter an integer untill user enters between 0 and 25
       // Read an integer into variable num1
       cout<<endl<<"Enter an integer between 0 and 25, inclusively : ";
       cin>>num1;
      
       if ( (0<= num1)&& (num1 <= 25)){
           //cout<<"between";
           break; // right valuse has been entered jump out of the loop
       }else if(0>num1) // Wrong input value entered, promting to reenter
           cout<<"ERROR : The integer you entered ("<<num1<<") is less then 0"<<endl;
       else if (num1 > 25)
           cout<<"ERROR : The integer you entered ("<<num1<<") is greater then 25"<<endl;
   }while(1);
  
   do{ // loop to promt user to enter an integer untill user enters between 0 and 25
       // Read an integer into variable num2
       cout<<endl<<"Now Enter a second integer between -15 and 30, inclusively : ";
       cin>>num2;
      
       if ( (-15<= num2)&& (num2 <= 30)){
           //cout<<"between;
           break; // right valuse has been entered jump out of the loop
       }else if (-15 > num2) // Wrong input value entered promting to reenter
           cout<<"ERROR : The integer you entered ("<<num2<<") is less then -15"<<endl;
       else if(num2 >30)
           cout<<"ERROR : The integer you entered ("<<num2<<") is greater then 30"<<endl;
   }while(1);
  
  
   // Read an operand +,-,*,/,or%
   cout<<endl<<"Enter arithmetic operation (+,-,*,/,or%) you'd like to perform : ";
   cin>>operand;
  
   switch(operand) {

       case '+':
                   result = num1 + num2;
                   showResult(result);
                   break;
                  
       case '-':
                   result = num1 - num2;
                   showResult(result);
                   break;
       case '*':
                   result = num1 * num2;
                   showResult(result);
                   break;
       case '/':   
                   showResult(result);
                   result = num1 / num2;
                   break;
       case '%':
                   result = num1 % num2;
                   showResult(result);
                   break;
       default :
          
           cout<<"ERROR :Operand entered is invalid, notable perform the requested operation."<<endl;
           break;      
   }
  
}

void showResult(int reslt){
  
   if (reslt == 0)
      cout<<"The result of the operation ("<<reslt<<") is Zero";
   else if (reslt < 0)
       cout<< "The result of the operation ("<<reslt<<") is Negative";
   else if (reslt > 0)
       cout<< "The result of the operation ("<<reslt<<") is Positive";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote