Help with re-running a simple programme

Hi, could someone tell me what is wrong here? Everything works, except each answer has the last answer added onto it. The programme is supposed to add the square of all the odd numbers between 0 and n. Thanks.

#include <iostream>

using namespace std;

int main()

{

int n,sumsq=0;
char choice3='Y';
while (choice3=='Y')

{




cout << "Enter a number: ";
cin >> n;
cout << "The sum of squared odd numbers smaller than ";
cout << n << " is ";
while (--n>0)
{
if (n%2-1) continue; sumsq += n*n ;

}
cout << sumsq<< "\n";
{
cout<<"Do you want to make another conversion? ( Y/N ) :";
cin>>choice3;
}




}

return 0;
}
1
2
3
4
int n ,sumsq=0;//-------\ 
char choice3='Y';     //|
while (choice3=='Y') {//|
    int sumsq = 0; //<--/	 
That causes this error: "error: 'sumsq' was not declared in this scope" for the two mentions of "sumsq" in the actual function, the programme still won't run. :(
Last edited on
EDIT: sorry, I forgot to put the last line in the function. Thanks kind stranger; it works now. :)
Last edited on
Topic archived. No new replies allowed.