hey everyone. I need to run a loop program that has 5 numbers input into it one at a time. it then needs to add any of the numbers that are multiples of three and display the sum. I've worked on it for a while and got kinda close but there are a few things wrong with my code, can anyone help?
#include <iostream>
using namespace std;
int main ()
{
int n, inputnumber, sum;
sum = 0;
inputnumber = 0;
cout << "enter a number";
cin >> n;
while (inputnumber<=4)
{
inputnumber = inputnumber + 1;
if(n%3==0)
{
sum = sum + n;
}
{
cout<< "enter another number";
cin>>n;
}
{
cout << "sum of multiples =" << sum << endl;
}
}
system ("pause");
return 0;
}
#include <iostream>
usingnamespace std;
int main ()
{
int n, inputnumber, sum;
sum = 0;
inputnumber = 0;
cout << "enter a number";
cin >> n;
// Added this
if(n%3==0)
{
sum = sum + n;
}
while (inputnumber<4) // changed this
{
inputnumber = inputnumber + 1;
{
cout<< "enter another number";
cin>>n;
}
if(n%3==0) // moved this
{
sum = sum + n;
}
{
cout << "sum of multiples =" << sum << endl;
}
}
system ("pause");
return 0;
}