Thanks!! Actually I did get it cleaned up and it works now. I just need some help adjusting the spaces. It comes out with spaces between each line, but I need to have the code display without spaces. (I hope that made sense)
Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void instructions(); //Instructions to the user.
void calculations(); //Calculates the area of a triangle or square.
int main ()
{
// Instructions for the user.
instructions();
// Calculates the area.
calculations();
calculations();
calculations();
calculations();
calculations();
calculations();
calculations();
calculations();
return 0;
}
-----------------------------------------------------------
// Instructions.
void instructions()
{
cout << "This program calculates the area of "
<< "either a square or a triangle. You will" << endl;
cout << "first be asked to enter a letter "
<< "(s for square, or t for triangle) to identify" << endl;
cout << "which kind of figure you want the area computed for. "
<< "Be sure to type a " << endl;
cout << "lower-case letter, and not a capital letter. "
<< "Then you will be asked for " << endl;
cout << "dimensions of the figure. Always hit the <Enter> "
<< "key after typing whatever " << endl;
cout << "has been asked for." << endl << endl;
} // End instructions.
-------------------------------------------------------------------
// Calculations.
void calculations()
{
int squ1, tri1, tri2, area;
char let1;
cout << "Type the letter s to compute the area of a square, "
<< "or type t for a triangle: ";
cin >> let1;
cout << endl;
if (let1 == 's')
{ cout << "Enter the length of a side for the square: ";
cin >> squ1;
if (squ1 <=0) //sanity check
{
cout << "It is impossible to have a square with "
<< "a side of "
<< squ1
<< endl << endl;
}
else
{
cout << endl;
area = squ1 * squ1; //calculate area
cout << "The area of a square with a side of "
<< squ1
<< " is "
<< area
<< endl << endl;
}
}
else if (let1 == 't')
{
cout << "Enter the length of the base for the triangle: ";
cin >> tri1;
cout << endl;
if (tri1 <=0) //sanity check
{
cout << "It is impossible to have a triangle with a "
<< "base whose length is "
<< tri1
<< endl << endl;
}
else
{
cout << "Enter the height of the triangle: ";
cin >> tri2;
cout << endl <<endl;
if (tri2 <=0) //sanity check
{
cout << "It is imppossible to have a triangle with a "
<< "height of "
<< tri2
<< endl << endl;
}
else
{
area = tri1 * tri2 / 2; //calculate area
cout << "The area of a triangle with a base of "
<< tri1
<< " and a height of "
<< tri2
<< " is "
<< area
<< endl << endl;
}
}
}
else
{
cout << "This program can only recognize the "
<< "lower-case letters s and t. Sorry." << endl <<endl;
}
return;
} // End calculations.