Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 3rd, 2005, 9:25 PM   #1
robert2513
Newbie
 
Join Date: Feb 2005
Posts: 9
Rep Power: 0 robert2513 is on a distinguished road
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
robert2513 is offline   Reply With Quote
Old Feb 4th, 2005, 12:00 AM   #2
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 5 lostcauz is on a distinguished road
I added
using namespace std;
after the include and it compiled and ran.
__________________
-- lostcauz

Stepped in what?...
Behind whose barn?...
I didn't even know they had a cow!
lostcauz is offline   Reply With Quote
Old Feb 4th, 2005, 2:57 AM   #3
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
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.
bl00dninja is offline   Reply With Quote
Old Feb 4th, 2005, 3:37 AM   #4
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
I myself am not a big fan of including std namespace as it does provide a lot of namespace pollution.
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC