| CODE |
#include <iostream> /*you can have it iostream.h as normal but it will give you a non fatal "antiquated" header error*/ using namespace std; /*you need to use this if you dont include the h on the end of the header*/ long value; /*makes a long variable which can store larger numbers than interger or int*/ int main() { cout<<"enter a number and i will tell you if it is odd or even"<<"\n"; /*prints instructions to the screen and makes a newline with the escape charachter \n*/ do{ /*starts DOing something (farily ovious isnt it?;) */ cin>>value; /*reads some keyboard input into the long variable value*/ switch (value % 2){ /*takes the value read in and divides it by 2 then returns the "left overs"-- either a 1 or a 0 another name for % is modulous*/ case 0: /*checks for a condition to be true */ cout<<"its a even number!"<<"\n"; /*outputs to the screen the results and makes a new line*/ break; /*breaks the switch and goes to while*/ case 1: /*checks for a condition to be true */ cout<<"its an odd number!"<<"\n"; /*outputs to the screen the results and makes a new line*/ break; /*breaks the switch and goes to while*/ } }while (1 != 2); /*does something while 1 is NOT EQUAL to 2 (this way it goes on forever) you can use a "sentinal value" to make the user be able to break the chain but i dident feel like including that*/ return 0; /*returns 0 to int main() i guess i dunno for sure :-/ */ } |
| CODE |
| using namespace std; |
| CODE |
| std::cout << "H World\n"; |
| CODE |
| using std::cout |
| CODE |
| switch (value & 1) |
| CODE |
| switch (value % 2) |
| CODE |
include <iostream> /* * you can have it iostream.h as normal but * it will give you a non fatal "antiquated" * header error. * * MIY Comment: * That's because iostream.h is there for historical * reasons to allow old programs to compile. It has * officially de deprecated and therefore may be * dropped with the next version of the compiler. * If this happens and you upgrade your code will fail * to compile. */ /using namespace std; sing std::cout; sing std::cin; /* * you need to use this if you dont include the h * on the end of the header * * MIY Comment. * This is because iostream.h will in-affect add the * stuff from the streams into the global namespace * (to be compatable with older code) while the correct * iostream will add the stuff into the standard (std) * namespace. * * There are alternatives. */ ong value; /* * makes a long variable which can store larger * numbers than interger or int * * MIY Comment. * This declares a global variable of type long. * long is an integer and the standard defines the * relative size of short, int and long as: * * short <= int <= long * * The actual size is up to the compiler and values * can actually very. * * To get the actual size try: * cout <<"sizeof(short) = "<<sizeof(short)<<"\n" * cout <<"sizeof(int) = "<<sizeof(int)<< "\n" * cout <<"sizeof(long) = "<<sizeof(long)<< "\n" * * On Windows you will get: * sizeof(short) = 2 * sizeof(int) = 4 * sizeof(long) = 4 * Thus on windows long is the same size as int. * PS. I will bet their are some compiler flags to * make long 8 bytes but I am not an MSVC expert. * * N.B. There is no type 'integer' */ int main() { /* * prints instructions to the screen and makes a newline with * the escape charachter \n */ cout<<"enter a number and i will tell you if it is odd or even"<<"\n"; do { /*starts DOing something (farily ovious isnt it?;) */ /* * MIY Comment: * Actually marks the start of a do loop. */ /* * reads some keyboard input into the long variable value * * MIY Comment: * Actually it reads from the standard input. * By default this is a keyboard but dont rely on this * always being true, sombody could have tied a file * to this stream, in that case you are reading from a file. * */ cin >> value; /* * takes the value read in and divides it by 2 then returns * the "left overs"-- either a 1 or a 0 another name for % * is modulous */ switch(value % 2) { case 0: /*checks for a condition to be true /* * outputs to the screen the results and makes a new line */ cout<<"its a even number!"<<"\n"; break; //breaks the switch and goes to while case 1: //checks for a condition to be true /* * outputs to the screen the results and makes a new line */ cout<<"its an odd number!"<<"\n"; break; //breaks the switch and goes to while } } while (1 != 2); /* * does something while 1 is NOT EQUAL to 2 * (this way it goes on forever) * you can use a "sentinal value" to make the user be able to break the * chain but i dident feel like including that * * MIY Comment: * A more standard way of doing this would be: * while(true) * This makes it easy for the compiler to spot infinite loops. */ return 0; // returns 0 to int main() i guess i dunno for sure :-/ /* * MIY Comment * The value returned is passed to the program that started this * one. Generally the operating system. * * A value of 0 means everything is OK. * Any other value is an indication of failure. */ } |
| QUOTE |
its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! its a even number! (so on).... |