Question: This code is not working properly, could you please check it out. I have been trying to solve it The sum of all integers between

This code is not working properly, could you please check it out. I have been trying to solve it

The sum of all integers between n1 and n2 inclusively

  • Ask the user to enter two numbers, n1 and n2, using the int data type.
  • Using any looping mechanism (determine which loop works best), calculate the sum of all numbers between n1 and n2

cout << "Enter a number:";

cin >> n1;

cout << "Enter a number:";

cin >> n2;

for(i = n1; i <= n2; i++)

{

sum += i;

}

cout << endl;

cout << "SUM: "<< sum << endl;

cout << endl;

break;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!