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;
}
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. :(