User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,631 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,254 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Oct 21st, 2005
Views: 1,405
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
cplusplus Syntax
  1. #include <math.h>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6. cout<<"This program will find the hypotenuse of a right triangle.\n";
  7. cout<<" |\\\n";
  8. cout<<" | \\\n";
  9. cout<<"A| \\C\n";
  10. cout<<" | \\\n";
  11. cout<<" ----\n";
  12. cout<<" B\n";
  13. int a, b, c, x, y, z, answer;
  14. starta: cout<<"Enter value of side A:";
  15. cin>> a;
  16. if (a<=0){cout<<"A side cannot to be less than or equal to 0\n";goto starta;}
  17. startb:cout<<"Enter value of side B:";
  18. cin>> b;
  19. if (b<=0){cout<<"A side cannot to be less than or equal to 0\n";goto startb;}
  20. cout<<" |\\\n";
  21. cout<<" | \\\n";
  22. cout<<a<<"| \\C\n";
  23. cout<<" | \\\n";
  24. cout<<" ----\n";
  25. cout<<" "<<b<<"\n";
  26. x=a*a;
  27. y=b*b;
  28. z=x+y;
  29. cout<<pow(a,2)<<"+"<<pow(b,2)<<"="<< z <<".\n";
  30. z=x+y;
  31. pow(z,0.5);
  32. cout<<" |\\\n";
  33. cout<<" | \\\n";
  34. cout<<a<<"| \\"<<sqrt(z)<<"\n";
  35. cout<<" | \\\n";
  36. cout<<" ----\n";
  37. cout<<" "<<b<<"\n";
  38. cout<<"Side C is "<< sqrt(z) <<".\n";
  39. system("PAUSE");
  40. return 0;
  41. }
Comments (Newest First)
manutd | Junior Poster in Training | Nov 21st, 2006
There are some outdated elements (goto), non-portable ones (system("PAUSE"), and a complete lack of indentation.
bumsfeld | Posting Shark | May 18th, 2006
Pythagoras is the man's real name.
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 2:01 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC