I trying to write a code that reads a set of integers and then finds and prints the sum of the even and odd integers. The numbers will be read in from the user via the cin statement. You do not know how many numbers the user may enter. When the user enters a 0 (zero), then the user is done entering numbers. I have most of the code finished, but i can't seem to get it to accuretly display when I enter the zero. This is what i have so far.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int even = 0;
int odd = 0;
int number;
int figure;
cout << "Insert your numbers and press enter" << endl;
cout<<"0 will terminate the program"<<endl;
cin >> number;
while (number != 0 )
{
figure = number % 10;
number = number / 10;
if(figure % 2 == 0)
even = even + figure;
else
odd = odd + figure;
}
cout << "The sum of the even integers is: " << even << endl;
cout << "The sum of the odd integers is: " << odd << endl;
return 0;
}