I'm trying to write a program for my class that computes the sum off all odd integers between 0 and n, a user defined arbitrary variable.
Everything should be ok except these blocks, which is where I'm guessing I'm having the issues...
... global variables
//Code:int n = 0;
int result = 0;
int newnum = 0;
int count = n;
//... computational code
while(count>=0) {
if(n % 2 ==1) { //if n is odd
result = n + newnum; //result updated
newnum = n; //newnum equal to new odd int n
n=n - 2; //n set to next odd number down
count = count - 1; //count updated
}
Else if(n % 2 == 0) { //if n is even
n = n - 1; //make n odd
count = count - 1; //continue subtracting counter
}
}
system.out.println(result)
system.exit(0)
So far, it does the first step of the program correctly as far as I can tell. If n is set to 5, it displays 8 (5+3). if n = 7, it displays 12 (7+5)
Why doesn't it continue?
Thanks in advance

