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.