**Objectives:**

To enable students to understand and
practice the concepts of:

- Variables
and operators
- Expressions
in C++
- Decision
structures
- Repetition
structures

**Assignment:**

Write a program that will

- Ask the user to enter lower limit and
upper limit in the form of integer numbers.
- The program will then
all those numbers between upper limit and lower limit (including the lower and upper limits) which are NOT multiple of 4.*add / sum* - This process should continue for all
the remaining integer numbers up until the upper limit is reached.
- The program will then show the
aggregate sum of all numbers for the given range.

Make sure that lower limit
entered by the user should be greater than zero. Also the upper limit value
entered by the user should be greater than the lower limit value.

Example:

Lower limit is 1 and Upper limit is 8 then
the program will subtract 4 and 8 as these are the multiples of 4. While add
remaining integers in the range (1+2+3-4+5+6+7-8 = 12). So, 12 is the
calculated number.

**Sample output for correct input:**

**Sample output for the wrong input:**

**Sample output for the wrong input:**

**Solution:**

#include<iostream>

using namespace std;

main()

{

int upperlmt, lowerlmt, sum = 0,
a;

cout << "Please Enter Lower
Limit <Greater Then 0 >: ";

cin >> lowerlmt;

if (lowerlmt > 0)

{

cout <<
"Please Enter
Upper Limit <Greater Than Lower Limit>: ";

cin >>
upperlmt;

if (upperlmt > lowerlmt)

{

for (a = lowerlmt; a
<= upperlmt; a++)

{

if
(a % 4 == 0)

{

sum = sum - a;

}

else

{

sum = sum + a;

}

}

cout << "Calculated
Number is "
<< sum << endl;

}

else

{

cout << "Upper Limit
Must Be Greater Than Lower Limit" << endl;

}

}

else

{

cout <<
"Lower Limit
Should Be Greater Then Zero" << endl;

}

system("pause");

}

## 0 Questions:

Post a Comment