Trouble using a loop structure

Hey guys, im in need of writing a program using loop structure that reads in 5 integers one by one , and calculates the sum of the values that are multiples of 3 and displays the result.

I have written this simple prgram, the only problem with it ofcourse is that it enters MANY integers until one that is not a multiple of 3 is entere (false statement). Any ideas would be much appreciated..



#include<iostream>
using namespace std;
int main ()
{
int num, total;
total = 0;

cout<<"Please input an integer : ";
cin>>num;
while (num%3==0)
{
total=total+num;
cout<<"please input an integer : ";
cin>>num;
}

cout<<"The total of the integers divisible by 3 is : "<<total<<endl;
system("pause");
return 0;
}
Last edited on
1
2
3
4
5
for(int count = 5; count > 0; count--)
{
      if(num%3==0)
           //........
}
#include<iostream>
using namespace std;
int main()
{
int num;
int counter = 0;
int total = 0;

do
{
cout<<"Please input an integer : ";
cin>>num;
if(num%3==0)
total=(total+num);
counter++;

} while (counter<5);

cout<<"The total of the integers that are multiples of 3 is "<<total<<endl;
system("pause");
return 0;
}




o hell yea..
Haha mate are you from uws
Topic archived. No new replies allowed.