I need to modify the following code so that instead, it calculates the mean of t
ID: 3640720 • Letter: I
Question
I need to modify the following code so that instead, it calculates the mean of two positive integers (n, n+1, n+2...m) where the user inputs the value for n and m. For example if the user inputs 2 and 9. the code would add 2+3+4+5+6+7+8+9/8 = 5.5Here is the original code:
#include <iostream>
using namespace std;
int main ()
{
int value;
int total = 0;
int number;
float mean;
cout << "Please enter a positive integer" << endl;
cin >> value;
if (value > 0)
{
for (number = 1; number <= value; number++)
{
total = total + number;
}
mean = float(total) / value;
cout << "The mean average of the first " << value << " positive integers is " << mean << endl;
}
else
cout << "Invalid input - integer must be positive" << endl;
return 0;
}