#include<iostream>
using namespace std;
int main()
{
int first, last, sum=0;
cout<<"Enter first and last value: ";
cin>>first>>last;
if(first %2== 0) first++;
for( int num=first; num<=last; num+2)
{sum = sum+num;}
cout<< "The sum of the numbers from "<<first<<"thru"<<last<<" ="<<sum<<endl;
system("pause")
}
when i run the program the only thing i get is "enter first and last value".
this won't even compile for( int num=first; num<=last; num+2)
should be for( int num=first; num<=last; num = num+2)
and you are missing a ; on this line system("pause")
no it won't I tried. I think maybe my post was a little misleading. I meant the code in general won't compile, not specifically the for loop. The missing ; won't allow it to compile.