473,749 Members | 2,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having some trouble with a Pythagorean Program.

I am writing an application to solve Pythagorean Theorum Problems. This
is on my own time, i am using a book to learn c++, and after doing a
fahrenheit to celsuis program from that book, i wanted to try to make
something all be meself.

I have it working great to find the hypotenuse, but am having some
dufficulty making it produce a missing leg. As you know, a^2 + b^2 =
c^2
I have a variable that does the input for the one of the legs subtraced
from the hypotenuse, but i dont know where to go from there. PLEASE
help me, thanks~~3than7

TTHIS IS THE C++ I WROTE
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main( int nNumberofArgs, char* pszArgs[])
{
int wwi;
cout << "Press 1 to find the hypotenuse, press 2 to find a missing
leg: ";
cin >wwi;
if (wwi == 1 ) {
int A;
int B;
//A^2 + B^2 = C^2 or the pythagorean Theorum
cout <<" Please enter A, do not square it!: ";
cin >A;
cout <<" Please enter B, do not square it!: ";
cin >B;

int C;
C = (A*A) + (B*B);

cout<< " C = ";
cout << C << " ";

cout << "";
cout << "";
}
if (wwi == 2) {
int Hypc;
cout << "Enter (C) the Hypotenuse: ";
cin >Hypc;
int Leg;
cout << "Enter one of the legs: ";
cin >Leg;

int F;
F = ( Hypc * Hypc ) - ( Leg * Leg ) ;


cout << "Missing leg is: ";
cout << << " " ;

}
system("PAUSE") ;
return 0;
}
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>.
~thanks again, 3than7

Dec 28 '06 #1
6 2035
psp

3t****@gmail.co m wrote:
I am writing an application to solve Pythagorean Theorum Problems. This
is on my own time, i am using a book to learn c++, and after doing a
fahrenheit to celsuis program from that book, i wanted to try to make
something all be meself.

I have it working great to find the hypotenuse, but am having some
dufficulty making it produce a missing leg. As you know, a^2 + b^2 =
c^2
I have a variable that does the input for the one of the legs subtraced
from the hypotenuse, but i dont know where to go from there. PLEASE
help me, thanks~~3than7

TTHIS IS THE C++ I WROTE
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main( int nNumberofArgs, char* pszArgs[])
{
int wwi;
cout << "Press 1 to find the hypotenuse, press 2 to find a missing
leg: ";
cin >wwi;
if (wwi == 1 ) {
int A;
int B;
//A^2 + B^2 = C^2 or the pythagorean Theorum
cout <<" Please enter A, do not square it!: ";
cin >A;
cout <<" Please enter B, do not square it!: ";
cin >B;

int C;
C = (A*A) + (B*B);

cout<< " C = ";
cout << C << " ";

cout << "";
cout << "";
}
if (wwi == 2) {
int Hypc;
cout << "Enter (C) the Hypotenuse: ";
cin >Hypc;
int Leg;
cout << "Enter one of the legs: ";
cin >Leg;

int F;
F = ( Hypc * Hypc ) - ( Leg * Leg ) ;


cout << "Missing leg is: ";
cout << << " " ;

}
system("PAUSE") ;
return 0;
}
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>.
~thanks again, 3than7
I see 2 bugs in this program:
1. You are printing the square of the leg, e.g. if hypotenuse is 10 and
one leg is 6 you are calculating only '64' not 8.
Same with your hypotenuse calculation you are calculating the square of
the hypotenuse.
Correction:
F = sqrt ( ( Hypc * Hypc ) - ( Leg * Leg ) ); // you need to link with
the math library on your OS

2. You are not printing the variable 'F':
cout << "Missing leg is: ";
cout << << " " ;
Correction: cout << "Missing leg is:" << F << endl;

Dec 28 '06 #2

<3t****@gmail.c omwrote in message
news:11******** *************@a 3g2000cwd.googl egroups.com...
>I am writing an application to solve Pythagorean Theorum Problems. This
is on my own time, i am using a book to learn c++, and after doing a
fahrenheit to celsuis program from that book, i wanted to try to make
something all be meself.

I have it working great to find the hypotenuse, but am having some
dufficulty making it produce a missing leg. As you know, a^2 + b^2 =
c^2
I have a variable that does the input for the one of the legs subtraced
from the hypotenuse, but i dont know where to go from there. PLEASE
help me, thanks~~3than7

TTHIS IS THE C++ I WROTE
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main( int nNumberofArgs, char* pszArgs[])
{
int wwi;
cout << "Press 1 to find the hypotenuse, press 2 to find a missing
leg: ";
cin >wwi;
if (wwi == 1 ) {
int A;
int B;
//A^2 + B^2 = C^2 or the pythagorean Theorum
cout <<" Please enter A, do not square it!: ";
cin >A;
cout <<" Please enter B, do not square it!: ";
cin >B;

int C;
C = (A*A) + (B*B);

cout<< " C = ";
cout << C << " ";

cout << "";
cout << "";
}
if (wwi == 2) {
int Hypc;
cout << "Enter (C) the Hypotenuse: ";
cin >Hypc;
int Leg;
cout << "Enter one of the legs: ";
cin >Leg;

int F;
F = ( Hypc * Hypc ) - ( Leg * Leg ) ;


cout << "Missing leg is: ";
cout << << " " ;

}
system("PAUSE") ;
return 0;
}
>>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>>>>>>>>>>> >>>>>.
~thanks again, 3than7
Do you remember how to do this with pen and paper?
You need to calculate square root(s).

Look up 'sqrt()' function.

-Mike
>

Dec 28 '06 #3

Yes i can do this on pen and paper, and one thing i forgot to ask is
how to find a square root in C++, but ill assume sqrt is what i use
for that

thanks to both of you , ill go try it right now

Dec 28 '06 #4

okay, when i use F = sqrt ( (Hypc*Hypc) - (Leg*Leg) );
i get this error

38 C:>>>>>`sqrt' undeclared (first use this function)
what needs to be done to fix this,
im a C++ Noob if you will

Dec 28 '06 #5

<3t****@gmail.c omwrote in message
news:11******** *************@n 51g2000cwc.goog legroups.com...
>
okay, when i use F = sqrt ( (Hypc*Hypc) - (Leg*Leg) );
i get this error

38 C:>>>>>`sqrt' undeclared (first use this function)
what needs to be done to fix this,
im a C++ Noob if you will
std::sqrt is probably in cmath.

http://dinkumware.com/manuals/?manua...math.html#sqrt
Dec 28 '06 #6
TY SO MUCH!
all of you who posted thanks a million

duane, that website will come in handy later too.

i added

#include <cmath>

and i changed the variable F from int to float

now it works perfectly, excpet with decimals
thaks a lot to all of you! ~3than7

Dec 28 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
3403
by: Jason Heyes | last post by:
A pythagorean triple is a triple <a,b,c> whose components are positive integers satisfying a*a + b*b = c*c. An example is <3,4,5> since 3*3 + 4*4 = 9 + 16 = 25 = 5*5. I want to write a function to extract pythagorean triples from an input stream. The input is formatted so that only the first two components <a,b> of a pythagorean triple are specified. The function signature will be: std::istream &operator>>(std::istream &is,...
11
4297
by: corwood | last post by:
I am in a VB .NET class, and one of the assignments is to use loops to generate a list of all the pythagorean triples where legA and legB <100 and hypotenuse < 200, and then put this list into a listbox. I have done this so far: 'Allocate some local variables Dim LegA As Integer Dim LegB As Integer Dim Hyp As Integer Dim Triple As String Dim Found As Integer
5
4716
by: stephanieanne2 | last post by:
The Problem: A right triangle can have sides that are all integers. The set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the relationship that the sum of the squares of two of the sides is equal to the square of the hypotenuse. Find all Pythagorean triples for side1, side2, and the hypotenuse that fall within a user-specified range. Limit the upper-bound to 500. Use a...
11
15056
by: inferi9 | last post by:
hi everyone I am new here and I have this C++ program that I have to write but it keep given me nothing useful. here is the question: A right triangle can have sides that are all integers. A set of three integer values for the sides of a right triangle is called a Pythagorean triple. These three sides must satisfy the following relationship: (side1)^2 + (side2)^2 = (hypotenuse)^2 Output all Pythagorean...
12
7424
by: abkierstein | last post by:
This is my 1st program and I need some help. I've almost got this one finished but I don't know where to go from here. There is something wrong with the sides I've assigned. Any tips? // Program: Pythagorean Theorem // Written by: Hellbreaker // // #include <iostream> #include <cmath> using namespace std;
3
4540
by: sab | last post by:
Hello, I have been working on a python script to parse a continuously growing log file on a UNIX server. The input is the standard in, piped in from the log file. The application works well for the most part, but the problem is when attempting to continuously pipe information into the application via the tail -f command. The command line looks something like this: tail -f <logfile| grep <search string| python parse.py
0
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8257
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6801
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6079
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2794
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2218
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.