SOURCE FILE: badIndentExample.html
Example of BAD FORMAT: How NOT to Indent Program Code
/*
This program inputs the cost of a product and its weight in ounces, and
then calculates and outputs the cost per ounce of the product.
*/
/* ******************************** */
/* ******************************** */
#include <iostream>
using namespace std ;
Example of BAD FORMATTING
int main (void)
{
double cost ;
double weight ;
double cost_per_ounce ;
cout << endl ;
cout << "Please enter the cost of the product (fixed decimal format): " ;
cin >> cost ;
cout << "Please enter the net weight of the product\n" ;
cout << "in ounces (positive number, fixed decimal format): " ;
cin >> weight ;
cost_per_ounce = cost / weight ;
cout << "When the cost is " << cost << " and the weight is " << weight << endl ; // This Line too long: stay under 79 chars
cout << "the cost per ounce is: " ;
cout << cost_per_ounce ;
cout << ".\n\n" ;
return 0;
}
/* ******************************** */
/* ******************************** */
#include <iostream>
using namespace std ;
Example of GOOD FORMATTING
int main (void)
{
/* indented 3 spaces within sets of enclosing braces { }
- be a 2-, 3-, 4-, or 5- SPACE indenter - NO TABS!
*/
double cost ;
double weight ;
double cost_per_ounce ;
cout << endl ;
cout << "Please enter the cost of the product (fixed decimal format): " ;
cin >> cost ;
cout << "Please enter the net weight of the product\n" ;
cout << "in ounces (positive number, fixed decimal format): " ;
cin >> weight ;
cost_per_ounce = cost / weight ;
cout << "When the cost is " << cost << " and the weight is "
<< weight << endl ;
cout << "the cost per ounce is: " ;
cout << cost_per_ounce ;
cout << ".\n\n" ;
return 0;
}
/* ******************************** */
/* ******************************** */