![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 9
Rep Power: 0
![]() |
Newbie Help with C++
Hello
I am currently enrolled in a C++ class and I am working an assigment. The assignment is: You are to write a C++ program that reads in values for m and n and prints the values of the Pythagorean triple generated by the following formulas: side1 = m * m - n * n side2 = 2mn hypotenuse = m * m + n * n Here is my code that I have written thus far: #include <iostream> int main() { int m, n, side1, side2, hypo; cout << "This program will calculate the values of a Pythagorean triple.\n"; cout << "What is the value of side a?\n"; cin >> m; cout << "What is the value of side b?\n"; cin >> n; side1 = (m*m)-(n*n); side2 = (m*n*2); hypo = (m*m)+(n*n); cout << "Side 1 is: "<<side1<<", Side 2 is: "<<side2<<", and the Hypotenuse is: "<<hypo<<"\n"; } When I go to compile the code, the complier says that: [robert@localhost ~]$ g++ pyth.cc /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../crt1.o(.text+0x18): In function `_start': : undefined reference to `main' collect2: ld returned 1 exit status [robert@localhost ~]$ I'm not sure whats wrong with the program. According to the error, something is wrong with "main" but I though main was a funtion that was built into C++. Any help would be appreciated. I am programming this in geditor in Fedora Core 3. Thanks. Robert2513 |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 5
![]() |
I added
using namespace std;
__________________
-- lostcauz Stepped in what?... Behind whose barn?... I didn't even know they had a cow! |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
without the namespace declaration, C++ doesn't know where to find "cout" and "cin"
if you wish NOT to use it then declare you funtion like this: std::cout or std::cin
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#4 |
|
Expert Programmer
|
I myself am not a big fan of including std namespace as it does provide a lot of namespace pollution.
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|