Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions