How can i add the odd numbers between the first number and the second number ?
thanks

[code]
#include<iostream>
using namespace std;

int main()

{
int i,sum=0,firstnum=1,secondnum=0;
char ch;

while(!(firstnum<secondnum))

{
cout<<"Enter starting number: ";
cin>>firstnum;
cout<<"Enter ending number(must be > startingnumber): ";
cin>>secondnum;
}
i=firstnum;
cout<<"The odd numbers between "<<firstnum<<" and"<<secondnum<<" are:\n";
while(i<=secondnum)
{
if(i%2==0)
sum+=i;
else
{
cout<<i <<""<< endl; //print odd numbers

}
i++;
}

system("pause");

return 0;

}
---
Last edited on
Don't do people's homework.
Hey Jibbz,

You are almost done with your code. You have your program printing out the odd numbers. All you need to do is figure out how to add them together.

 ``123456789101112131415161718192021222324252627282930313233343536`` ``````#include using namespace std; int main() { int i,sum=0,firstnum=1,secondnum=0; char ch; while(!(firstnum>firstnum; cout<<"Enter ending number(must be > startingnumber): "; cin>>secondnum; } i=firstnum; cout<<"The odd numbers between "<
Topic archived. No new replies allowed.