//The following is a collection of examples of how to display
//things on the screen (output) and get input from the keyboard. The
//examples are bundled together as if part of a large program, but they
//really are not related to each other and the "program" makes no sense.
//You might copy+paste part or all of this code into the compiler to
//experiment with it, or you might just print it out.
#include <iostream.h> // needed for cout, cin
#include <stdio.h> // needed for printf
void main()
{
cout << "Hello, world!"; // display "Hello, world!"
cout << endl; // skip to the next line--the
// computer will not automatically
// go to the next line; must be told
cout << "Hello, " << "world!"; // same thing--note the chaining
cout << endl;
cout << "Hello, world!" << endl; // same thing, chaining the endl
cout << "Hello, world!\n"; // \n is a "control sequence"; it is
// a two-symbol combination used to
// represent something for which there
// is no symbol
cout << "A" << endl << endl // display: A
<< "B" << endl << endl //
<< "C" << endl; // B
//
// C
// note above: it is legal to break up a single command over several
// lines; the semicolon at the end of the command tells the computer
// when to finish
cout << "A\n\nB\n\nC\n"; //shorter version of above
///////////////////////////////////////////
// more control sequences
// \n == newline (skip to next line)
// \a == beep
// \t == tab
// \\ == display backslash
// \" == display quote
// \0 == null character
cout << "I'm done!\a\a\n"; //display "I'm done" and beep
cout << "13\t5231\n"; // 13 5231
cout << "5\t34\n"; // 5 34
cout << "621\t982\n"; // 621 982
cout << "You must use \\n...\n"; // You must use \n...
cout << "Bill \"The Geek\" Gates\n"; // Bill "The Geek" Gates
///////////////////////////////////////////
// printf, functional notation, old C
printf("Hello, world!\n");
//NOTES:
//(1) "print with formatting"; used in original C language
//(2) requires use of #include <stdio.h>
//(3) can do some things better than cout
//(4) must use \n with this command; endl has no place
//(5) functional notation; like in high school math:
// f(x)=x+6 f(3)=3+6=9
// printf(x) displays something
///////////////////////////////////////////
// displaying raw numbers
cout << 3 << endl; // displays 3
cout << 12 << 98 << endl; // displays 1298
cout << 12 << " " << 98 << endl; // displays 12 98
cout << 12;
cout << 98;
cout << 53 << endl; // displays 129853
// displaying variables
int x,age;
x=3;
cout << x << endl; // displays 3 (value of x)
cout << x << x << endl; // displays 33
// getting input from keyboard
cout << "Enter your age: ";
cin >> age; // cin gets input from keyboard
cout << "You are " << age << " years old!" << endl;
cout << age << x << age << endl; // displays values of age, x, and age
char name[100]; // sequence of commands to get a
cout << "Enter your name: "; // name; uses an array of characters
cin >> name; // (covered later in course)
cout << "Hi " << name << "!";
cin >> x >> age; // possible to chain inputs, too
}