#1
hey UG, so i have to make a program that tells you if the number you type in is a positive pair number using the "if" instruction and i dont know where to begin...any ideas?

Thanks in advance and sorry for my bad english. Saludos de Tijuana
#2
if
{ x>0;
printf ("positive");
}
else;
{
printf ("negative");
}

my programming was a yr ago, sumthin similar to that, is how we did it.. if i get your question correctly
Sell and Promote your music TuneHub!



wy is yer mad at muy gramhar fer?


Quote by jimmyled
jimmybanks youre a genius.


aparently i ar smrt?
Quote by dyingLeper
jimmybanks youre a genius


GO SENS GO
Last edited by JimmyBanks6 at Oct 14, 2009,
#3
thank you Jimmy, how about getting c++ to tell me if that same number is a pair number or impair number...

Thank you in advance
#4
Quote by Deth_send
thank you Jimmy, how about getting c++ to tell me if that same number is a pair number or impair number...

Thank you in advance

I'm not sure what you mean by pair or impair. If you could explain a little further I might be able to help you. From what I've seen, C++ if statements are almost exactly like Java's, so I should be of some use.
Lift not the painted veil which those who live
Call life; though unreal shapes be pictured there,
And it but mimic all we would believe
#5
hmm i think its similar to you set the value to a long, then you divide the x value by 2, if it results in a whole number you set it to print pair, if it is a decimal value, then you set it to print impair, i cant remember exactly the programming but that should be enough info for you to play around and get it

that is if you mean by pair:even, impair: odd . that is what i thought you meant?
Sell and Promote your music TuneHub!



wy is yer mad at muy gramhar fer?


Quote by jimmyled
jimmybanks youre a genius.


aparently i ar smrt?
Quote by dyingLeper
jimmybanks youre a genius


GO SENS GO
Last edited by JimmyBanks6 at Oct 14, 2009,
#6
sorry my english is very crappy, by pair number i mean like 2,4,6,8,10,12 etc.. and impair numbers i mean like 1,3,5,7,9,11,13 etc... thanks again for your quick response
#7
You're all WRONG...

Use the modulo (%) operator. If the number modulo 2 returns 1, print impair and if it returns 0, print pair.
#8
if((x%2)==0)
cout << "Even";
else
cout << "Odd";

done.

^^ shakes fist at guy above me.
#9
Quote by joemama9119
if((x%2)==0)
cout << "Even";
else
cout << "Odd";

done.


ohh wow as if i forgot the %.. meh mechanical eng dont need programing
Sell and Promote your music TuneHub!



wy is yer mad at muy gramhar fer?


Quote by jimmyled
jimmybanks youre a genius.


aparently i ar smrt?
Quote by dyingLeper
jimmybanks youre a genius


GO SENS GO
#10
Quote by Deth_send
sorry my english is very crappy, by pair number i mean like 2,4,6,8,10,12 etc.. and impair numbers i mean like 1,3,5,7,9,11,13 etc... thanks again for your quick response

Ah okay, in that case it should go something like this (int x set to whatever number you're evaluating):

int x;

if(x % 2 == 0){
cout<<"pair"<<endl;
}else if(x % 2 == 1){
cout<<"pair"<<endl;
}

I believe that's correct syntactically. If not you might have to play around with it a little. The '%' is the modulus operator, which returns the remainder after dividing by the following number, so if it's one, the number is odd, and if it's zero, the number is even.

EDIT: Wow, I got beat. That'll teach me not to respond with a novel.
Lift not the painted veil which those who live
Call life; though unreal shapes be pictured there,
And it but mimic all we would believe
Last edited by Ajax413 at Oct 14, 2009,
#11
Use the if and the mod ( % ) function, the mod function returns the difference of a divison. So 5 % 2 = 1, because 5 = 2*2 + 1. Hope you understand...
A pair number is dividable by 2, so x % 2 == 0, and odd ( impair ) number is not so
x % 2 != 0.

if( (x % 2) == 0) cout << "Even";
if ( (x% 2) != 0) cout <<"Odd";

if you have questions just ask.