Hi guys. Ive tried several ways of doing this program, taking 4 numbers, then adding the even together , then the odd. I keep getting weird answers. Also, I'm sure you can convert the value of one variable to another, but was wondering on the rule, which goes on the left of the = sign, and which goes on the right.
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int number1,number2,number3,number4;
int even1,even2,even3,even4;
int odd1,odd2,odd3,odd4;
int totalEven;
int totalOdd;
cout<<"Please enter 4 numbers, and we will add the even's together, and the odd's together "<<endl;
cout<<"Enter your first number "<<endl;
cin>>number1;
cout<<"Enter your second number "<<endl;
cin>>number2;
cout<<"Enter your third number "<<endl;
cin>>number3;
cout<<"Enter your fourth number "<<endl;
cin>>number4;
if(number1 % 2 == 1) //modulus gives remainder;
//if you divide first number 2 and get a remainder of 0, its even. If remainder of 1, its odd
{
odd1= number1;
}
if(number2 % 2 == 0)
{
even1=number1;
}
if(number2 % 2 == 1)
{
odd2=number2;
}
if(number2 % 2 == 0)
{
even2=number2;
}
Thanks, JLBorges, now I need to go through your code line by line to understand it. The std::cout isnt necessary if I put the "using namespace std;" at the top, right? I've seen this form a lot, still don't quite understand why it's not all done the same.
Thanks a lot, I'm starting to have my normal day thinking being preceded by cout<<, so I guess I need a break, but this gives me a direction to understanding this program (I'm only 4 weeks in the class).