Compare two numbers

Tech-Archive recommends: Fix windows errors by optimizing your registry



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


.



Relevant Pages

  • Re: Math.random()
    ... private final Random rand = new Random; ... public Set <Integer> scrambleEggs(int upper, ...
    (comp.lang.java.help)
  • Re: Compare two numbers
    ... I want to input two numbersto compare them. ... Then set the lower one as the lower limit,and the upper one as the upper ... int main ... Remove del for email ...
    (microsoft.public.vc.language)
  • Re: Compare two numbers
    ... Then set the lower one as the lower limit,and the upper one as the upper ... int main ... The assignment operator assigns the right-hand side to the left-hand side, ... Uninitialized local variables start off ...
    (microsoft.public.vc.language)
  • Re: bytes calculation
    ... sizeof returns the number of chars in an object ... If the upper half of scnlen contains a value within the range of the upper ... int, bad things could happen, no? ...
    (comp.lang.c)
  • Re: String or string
    ... uses an upper case "S" and the other uses a lower case "s". ... appears in a light green color, while the lower case appears as blue. ... String and string mean the same thing but are in two different series of names. ... can be said for int but it has a few caveats, e.g. if you are working in a code base where you delve in and out of using 32 and 64 bit ints then it may ...
    (microsoft.public.dotnet.languages.csharp)