Quick Question

I have this program below and my question is: Would I change the Total = Total + N; ?? I've tried changing it a few times but it won't give me 40 or 45. Does anyone have any reference codes for an example?


/*
Program: fixit2a - This program prompts for L and H and computes the Total
of the numbers between L and H inclusive.
Examples: L is 5 H is 10: Total: 45
L is 6 H is 10: Total: 40
The program does not work. Correct the program.
DO NOT DELETE OR ADD LINES.
You may modify lines, but DO NOT change while to for
*/
#include <iostream>
using namespace std;

int main(void)
{
int L, H, N, Total = 0;

cout << "Enter L and H: ";
cin >> L >> H;

N = 0;
while (N <= L)
{
Total = Total + N;
N = N + 1;
}

cout << Total << endl;

return 0;
}
its while N is L or bigger, until it gets to H, with N starting at L value, not 0
You need to start at L and increment L until it's equal to H.

What you're doing is summing the numbers from 0 to L, inclusive.
Ouch, assignment: "debug this code".

So, what would you do to make N equal L and then increment N up to H?

Hint: you only need to make changes to two lines.
Last edited on
Topic archived. No new replies allowed.