Tuesday, July 28, 2009

C++ Help With "If" Statements?

In an "if" line - how do I use NOT (!) properly? I wanted to make a program that would ask the user to input a number other than 4? It would have if !4 it would say well done and and ELSE that says that they have entered 4. Basically I want to see how you use the boolean operator ! :-D

C++ Help With "If" Statements?
#include%26lt;iostream%26gt;


using namespace::std





void main(){


cout%26lt;%26lt;"Plz enter a number"%26lt;%26lt;endl;


int x;


cin%26gt;%26gt;x;


if(x!=4)


{


cout%26lt;%26lt;"Well Done"%26lt;%26lt;endl;


}


else {


cout%26lt;%26lt;"The Number You Entered is 4"%26lt;%26lt;endl;


}





};





I GUESS THIS IS WHAT YOU MEAN. YOU DONT NEED A BOOLEAN OPERATOR IN THIS CASE.
Reply:#include%26lt;stdio.h%26gt;





int main(void)


{


int a, b;





if (a = 1; a %26gt; 0; a--)


{


printf("Give me your number please");


scanf("%d", %26amp;b);








if (b != 4) // or (b %26lt;%26gt; 4)


printf("Well Done");





else


printf("Wrong number!");





}





return 0;





}








I'm not sure tho, it's been a while since i've used C;)
Reply:if (x !=4)


printf("welldone");


else


printf("you have entered 4");


the rest of the coding is up to u


No comments:

Post a Comment