Hello all, I just started using c++ and I'm supposed to write a function that takes two positive integers, p and q, where p<q, and i have to return the sum of all the numbers >=p and <=q which are divisible by 7.
here's what i have so far:
# include <iostream>
using namespace std;
int d7 (int p, int q, int &s);
int main ()
{
int p=0;
int q=0;
int s=0;
cout << "Enter two positive integers" <<endl;
cin >> p;
cin >> q;
d7 (p,q,s);
cout <<s<<endl;
system ("pause");
return 0;
}
int d7 (int p, int q, int &s)
{
while (p<q) {
if(p%7==0, q%7==0){
s+=(p+q);}
q--;
}
}
But it doesn't work!!! Help please...