I have this question.,i tried it and it worked at first. But i dont know what happened today, it wont work. could someone please find the error.
Write a program that allows the input of an integer value n and displays all multiples of 3 which are less than or equal to n, as well as the sum of the square of these values.
#include <iostream>
using namespace std;
int main()
{
int i,n;
float sum;
i=1;
cout<<"Enter value of n: ";
cin>>n;
while (i<=n){
if (i%3 == 0){
cout<<"i: "<<i<<endl;
sum+=i*i;
}
i++;
}
cout<<"The sum of the square of all multiples of 3 less than or equal to "<<n<< " is: "<<sum<<endl;
return 0;
}