In: Computer Science
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for improving the readability of your code. Your program should have the following interface.
Please find below code and don't forget to give a Like.
Please refer below screenshot for code and output.
Code:
#include <iostream>
using namespace std;
int main()
{ int num,num3,num5,num_3,temp;
cout<<"Enter a Number:";
cin>>num;
for(int i=0;i<5;i++){
num++;
if(i==2){
num_3=num;
}
}
temp=num_3;
num5=num;
int j=8;
while(j>0){
num--;
j--;
}
num3=num;
cout<<"num+5 value is:"<<num5<<endl;
cout<<"num-3 value is:"<<num3<<endl;
num_3--;
num_3--;
cout<<"(num+3)-2 value is:"<<num_3<<endl;
cout<<"(num+5)*2/(num+3) value
is:"<<(num5*2)/temp<<endl;
return 0;
}
Output: