Compare two numbers
- From: "Elynis Zhou" <elynis_zhou@xxxxxxxxxxxxx>
- Date: Sat, 2 Feb 2008 22:11:01 +0800
Hi everyone,
I want to input two numbers(int style) to compare them.
Then set the lower one as the lower limit,and the upper one as the upper
limit.And add the lower to the upper one.But whatever I input,the programme
always display "Sum of -858993460 to -858993460 is -1717986920. The code is
as followed,
#include <iostream.h>
int main()
{
cout<<"Enter two numbers:";
int v1,v2;
cin>>v1>>v2;
int lower,upper;
if(v1<=v2){
v1=lower;
v2=upper;
}
else
v1=upper;
v2=lower;
int sum;
for (int val=lower;val<=upper;++val)
sum+=val;
cout<<"Sum of"<<lower<<" to"<<upper<<" is"<<sum<<endl;
return 0;
}
Thanks in advance,
Ely
.
- Follow-Ups:
- Re: Compare two numbers
- From: Barry Schwarz
- Re: Compare two numbers
- From: Doug Harrison [MVP]
- Re: Compare two numbers
- Prev by Date: Re: IUnknown
- Next by Date: virtual function not in vtable
- Previous by thread: Re: Virtual function and multiple inheritance
- Next by thread: Re: Compare two numbers
- Index(es):
Relevant Pages
|