Question:
i need help in c++ about if statement?
Emad
2009-11-01 08:13:26 UTC
program that reads two numbers and print whether none, one or both of them are even.
code I write is

#include

using namespace std;

int main ()
{
float x,y;
cout<<"Pls enter two numbers"< cin>>x>>y;
int z;
float k;
if (x/2==z && y/2==z)
cout< else if (x/2==z)
cout< else if (y/2==z)
cout< else if (x/2==k && y/2==k)
cout<<"None";
system("pause");
return 0;
}
something wrong with if statement
Three answers:
t.trowbridge
2009-11-01 10:07:22 UTC
include



using namespace std;



int main ()

{

int x,y;



cout << " Please enter two numbers: ";

cin >> x >> y;



if (x%2 == 0 && y%2==0)

cout << x << " & " << y <<" are even.";



else if (x%2 == 0)

cout << x << " is even.";



else if (y%2 == 0)

cout << y << " is even.";



else

cout << "Neither are even.";



return 0;

}
2009-11-01 16:21:48 UTC
You haven't defined "k", you're just asking if z/2 is equal to an empty space.



Try "x%2 == 0".
Ratchetr
2009-11-01 16:30:39 UTC
z isn't initialized. It could have any value, but probably not the one you want. Set it to 0


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...