Quick C++ Question

This program prompts for F and G and computes the Total
of the numbers between F and G inclusive.
Examples: F is 5 G is 10: Total: 45
F is 6 G is 10: Total: 40

Would I change the Total + Total + N or the for loop??? and should I change the letters to the numbers assigned to them??

#include <iostream>
using namespace std;

int main(void)
{
int F, G, Total = 0;

cout << "Enter F and G: ";
cin >> F >> G;

for(int N = G; N <= F; N++)
{
Total = Total + N;
}

cout << Total << endl;

return 0;
}
I'm not sure what you are asking but you are on the right track. Reference the code below for help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

int main(void)
{
	int low, high, Total = 0;

	cout << "Enter F and G: ";
	cin >> low >> high;

	for (int count = low; count <= high; count++)
	{
		Total += count;
	}

	cout << Total << endl;

	return 0;
}
Topic archived. No new replies allowed.