A simple stream input and output using cin and cout C++ program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Comparing an age of two person in demonstrating the standard input stream reading and output stream writing in C++ programming
To show: How to compare an age of two person in demonstrating the standard input stream reading and output stream writing in C++ programming
// a simple stream input/output
#include <iostream>
using namespace std;
int main(void)
{
int myAge, friendAge;
cout<<"Enter your age: ";
cin>>myAge;
cout<<"Enter your friend's age: ";
cin>>friendAge;
if(myAge > friendAge)
cout<<"You are older.\n";
else
if(myAge < friendAge)
cout<<"You are younger.\n";
else
cout<<"You and your friend are the same age.\n";
return 0;
}
Output examples:
Enter your age: 99
Enter your friend's age: 23
You are older.
Press any key to continue . . .
Enter your age: 23
Enter your friend's age: 99
You are younger.
Press any key to continue . . .
Enter your age: 23
Enter your friend's age: 23
You and your friend are the same age.
Press any key to continue . . .