I know this is a mess... I got parts of it to work (the square part) but when I add in triangle...I get lots of errors
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(); 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; char let1; float areas; float areat; cout << "Type the letter s to compute the area of a square, " << "or type t for a triangle: "; cin >> let1; if (let1=='s'){ cout << "Enter the length of a side for the square: "; cin >> squ1; if (squ1 > 0) {//Calculates the area of a square areas = (squ1 * squ1); cout << "The area of a square with a side of " << squ1 << " is " << areas << endl;} else (squ1 <= 0) {cout << "It is impossible to have a square with a side << "whose length is " << squ1 << endl;} else if (let1=='t'){ cout << "Enter the length of the base for the triangle: "; cin >> tri1; //Calculates the area of a triangle areat = (.5 * tri1 * tri1); cout << "The area of a triangle with a base of " << tri1 << " and a height of " << tri1 << " is " << areat << endl; } else { cout << "This program can only recognize the " << "lower-case letters s and t. Sorry." << endl; } return; } // End calculations.



LinkBack URL
About LinkBacks


