/* C version */
#include <stdlib.h>
int main(void)
{
int age = 0;
printf("How old are you?: ");
scanf("%d", &age); // %d = decimal number, &age = pointer to variable "age"
if( age == 0)
printf ("ERR: Please enter your age!\n");
else
printf("You are %d years old.\n", age);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* C++ version */
#include <iostream>
usingnamespace std;
int main(void)
{
int age = 0;
cout << "How old are you?: ";
cin >> age;
if( age == 0 )
cout << "ERR: Please enter your age!\n";
else
cout << "You are " << age << " years old.\n";
return 0;
}