I had to write a program that accepted five numbers from the user. Then it will display the number of odd and even numbers, and a total sum of all numbers.
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int c;
int d;
int e;
int sum;
int remainder;
int bremainder;
int cremainder;
int dremainder;
int eremainder;
int even;
int odd;
int total = 0;
int Ototal = 0;
cout << "Please enter the 5 numbers you would like calculated: \n";
cin >> a;
cin >> b;
cin >> c;
cin >> d;
cin >> e;
remainder = a % 2;
bremainder = b % 2;
cremainder = c % 2;
dremainder = d % 2;
eremainder = e % 2;
sum = (a + b + c + d + e);
if (remainder = 0)
{
total+=remainder;
}
else {
Ototal += remainder;
}
if (bremainder = 0)
{
total += bremainder;
}
else {
Ototal += bremainder;
}
if (cremainder = 0)
{
total += cremainder;
}
else {
Ototal += cremainder;
}
if (dremainder = 0)
{
total += dremainder;
}
else {
Ototal += dremainder;
}
if (eremainder = 0)
{
total += eremainder;
}
else {
Ototal += eremainder;
}
cout << total << "\n";
cout << Ototal << "\n";
cout << sum << "\n";
system("PAUSE");
return 0;
}
=
in C/C++ does NOT serve as comparision! And if it did, then after satisfying e.g. 'cremainder
equals zero' it doesn't make sense to addcremainder
tototal
, because adding zero tototal
does not change thetotal
value. \$\endgroup\$