-Write a program using while loops that prompts the user for a set of integers.
-Your program will ask for one integer at a time. If the number 0 is entered, the list is complete and your program will output two results: the sum of the even integers and the sum of the odd integers.
-After each integer is entered by the user, your program will print out whether the integer entered by the user is less than, equal to, or greater than the previous integer. Assume for the first integer entered by the user that the “previous integer” was 0.
-Your program must handle a variable number of inputs (in other words, you cannot hard code for the test cases).
#include <iostream>
usingnamespace std;
int main()
{
int a;
int b;
a = 1;
b = 0;
while (a != 0) {
cout << "Please enter an integer: ";
cin >> a;
if (a > b) {
cout << "New integer is greater than previous." << endl;}
if (a < b) {
cout << "New integer is less than previous." << endl;}
if (a = b) {
cout << "new integer is equal to previous." << endl;}
}
a = b;
}
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int a;
int b;
int sum_odds;
int sum_evens;
a = 1;
b = 0;
sum_odds = 0;
sum_evens = 0;
while (a != 0) {
cout << "Please enter an integer: ";
cin >> a;
if (a % 2 == 0) {
sum_evens = sum_evens + a;
}
if (a % 2 != 0) {
sum_odds = sum_odds + a;
}
if (a >= b) {
if (a > b) {
cout << "The integer is greater than the previous." << endl;
}
else {
cout << "The integer is equal to the previous." << endl;
}
}
if (a < b) {
cout << "The integer is less than the previous." << endl;
}
b = a;
}
cout << "The total of the even numbers is " << sum_evens << "." << endl;
cout << "The total of the odd numbers is " << sum_odds << "." << endl;
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int a;
int b;
int sum_odds;
int sum_evens;
a = 1;
b = 0;
sum_odds = 0;
sum_evens = 0;
bool flagfirst=0;
while (a != 0) {
cout << "Please enter an integer: ";
cin >> a;
if (a % 2 == 0) {
sum_evens = sum_evens + a;
}
if (a % 2 != 0) {
sum_odds = sum_odds + a;
}
if(flagfirst==0 || a==0)
{
flagfirst=1;
b=a;
}
else
{
if (a >= b) {
if (a > b) {
cout << "The integer is greater than the previous." << endl;
}
else {
cout << "The integer is equal to the previous." << endl;
}
}
if (a < b) {
cout << "The integer is less than the previous." << endl;
}
}
b = a;
}
cout << "The total of the even numbers is " << sum_evens << "." << endl;
cout << "The total of the odd numbers is " << sum_odds << "." << endl;
return 0;
}