Pythagorus

ShawnCplus 0 Tallied Votes 189 Views Share

Well its fairly self explanatory, its a program that shows that calculates the hypotenuse using the pythagorean theorum, It displays the values of the sides and shows a crappy ascii art right triangle with the values input and the later found values

#include <math.h>
#include <iostream>
using namespace std;
int main()
{
cout<<"This program will find the hypotenuse of a right triangle.\n";
cout<<" |\\\n";
cout<<" | \\\n";
cout<<"A|  \\C\n";
cout<<" |   \\\n";
cout<<"  ----\n";
cout<<"   B\n";
int a, b, c, x, y, z, answer;
starta: cout<<"Enter value of side A:";
cin>> a;
if (a<=0){cout<<"A side cannot to be less than or equal to 0\n";goto starta;}
startb:cout<<"Enter value of side B:";
cin>> b;
if (b<=0){cout<<"A side cannot to be less than or equal to 0\n";goto startb;}
cout<<" |\\\n";
cout<<" | \\\n";
cout<<a<<"|  \\C\n";
cout<<" |   \\\n";
cout<<"  ----\n";
cout<<"   "<<b<<"\n";
x=a*a;
y=b*b;
z=x+y;
cout<<pow(a,2)<<"+"<<pow(b,2)<<"="<< z <<".\n";
z=x+y;
pow(z,0.5);
cout<<" |\\\n";
cout<<" | \\\n";
cout<<a<<"|  \\"<<sqrt(z)<<"\n";
cout<<" |   \\\n";
cout<<"  ----\n";
cout<<"   "<<b<<"\n";
cout<<"Side C is "<< sqrt(z) <<".\n";
system("PAUSE");
return 0;
}
bumsfeld 413 Nearly a Posting Virtuoso

Pythagoras is the man's real name.

manutd 2 Junior Poster

There are some outdated elements (goto), non-portable ones (system("PAUSE"), and a complete lack of indentation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.