help with loops

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;
}
I modified your program a little to hopefully give you what you want:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>

using namespace 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;
}
thanks, thats what i was aiming for. How can i change it further to make the results be displayed at the end rather than during each step?
Just move your output line outside of the while loop. In this case, move it to the line before your system("pause");
Topic archived. No new replies allowed.