so if i put in 1 and 3 then it should add 1+2+3 for an output of 6.
what im struggling with, is the loop i need to use(teacher said i have to) in the second function called sumTo.
#include <iostream>
using namespace std;
int sumTo(num1, num2);
int main ()
{
int num1;
int i;
int num2;
int sumTo = 0;
cout << "Please enter 2 numbers: ";
cin >> num1 >> num2;
cout << "The sum of the numbers between " << num1 << " and " << num2 << " = " << sumTo(num1, num2) << endl;;
return 0;
}
int sumTo(num1, num2)
{
for (int = num1; i < num2; i++)
{
sumTo += i;
}
}
i dont think that "for" loop is right at all, but i couldnt think of any other way
im also getting an error that num1 and num2 are undeclared, although i did declare them in main
and theres a few other minor problems im guessing.
i think i have "creating functions" topic understood, but now im running into another problem.
thanks for your help if you can work me through the issue im having here


Sign In
Create Account


Back to top









