Next: Summary
Up: A simple C++ program
Previous: Input and Output
As was remarked in note 6.4 above, any number of spaces and or new lines can be used to separate the different symbols in a C++ program. The identifiers chosen for variables mean nothing to the compiler either, but using identifiers which have some significance to the programmer is good practice. The program below is identical to the original example in this Lesson, except for its layout and the identifiers chosen. Which program would you rather be given to modify?
#include <iostream.h> void main( ) { int a,b, c,d; cout << "Length = "; cin >> a; cout<<"Width = " ;cin >> b; c = 2*(a+ b); d = a*b; cout << endl << "Perimeter is " << c << endl << "Area is " << d << endl;}