I am new to programming and bought Jumping into C++ by Alex Allain. I am working through the practice problems and was hoping someone could take a look at this and let me know if I am writing the code in an appropriate format.
My program compiles and runs fine. I just do not want to get into any bad habits. Any reviews would be greatly appreciated.
Thanks,
Kranky
Code:#include <iostream> using namespace std; // Chapter 4 practice problem 1 // Ask the user for two users' ages and indicate who is older // Behave differently if both are over 100 int main() { int age1; int age2; cout << "This program will compare two ages and let you know which is older\n"; cout << "Enter age 1: "; cin >> age1; cout << "Enter age 2: "; cin >> age2; if ( age1 < age2 ) { cout << "Age 1 is younger than Age 2\n"; } else if ( age1 == age2 ) { cout << "They are both the same age!\n"; } else { cout << "Age 2 is younger than Age 1\n"; } if ( age1 > 100 && age2 > 100 ) { cout << "They are both very old!\n"; } }