Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 10-18-2001, 01:16 PM   #1
Member (7 bit)
 
raja's Avatar
 
Join Date: Oct 2001
Location: Macon, Georgia
Posts: 93
Send a message via ICQ to raja Send a message via AIM to raja
C++ program won't work!

Here's my code:

#include

main ()
{
//declare variables
char name[21];
char address[21];
char city[21];
char state[21];
char zip[11];
char phone[12];

// get all variables
cout << "Enter your name: ";
cin.get(name, 21);
cin.ignore(80,'\n');
cout << "Enter your address: ";
cin.get(address, 21);
cin.ignore(80,'\n');
cout << "Enter your city: ";
cin.get(city, 21);
cin.ignore(80,'\n');
cout << "Enter your state: ";
cin.get(state, 21);
cin.ignore(80,'\n');
cout << "Enter your zip: ";
cin.get(zip, 11);
cin.ignore(80,'\n');
cout << "Enter your phone number: ";
cin.get(phone, 12);
cin.ignore(80,'\n');

/***************************************
* output all variables in this format: *
* Name *
* Address *
* City, State, ZIP Code *
* Phone Number *
***************************************/

cout << name << '\n';
cout << address << '\n';
cout << city << ", " << state << ", " << zip << '\n';
cout << phone << '\n';

return 0;
}

For some reason, it won't work. Please help!! It compiles okay, but when I try and link it, I get this error message:

"personal info.obj : error LNK2005: _main already defined in string.obj
Debug/string.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe."

Please help.. my teacher is retarded and doesn't know a damn thing about C++!! Our book doesn't help, and the compiler we're using (Microsoft Visual C++ 6.0) doesn't tell me how to fix my "multiply defined symbols." Any advice would be greatly appreciated!!!
raja is offline   Reply With Quote
Old 10-18-2001, 01:37 PM   #2
Member (6 bit)
 
KoOk's Avatar
 
Join Date: Oct 2001
Location: Canada
Posts: 53
Wink

//Dude you missed a few things at the beginning, make sure you have your header
files in


#include
using namespace std;

int main ()
{
//declare variables
char name[21];
char address[21];
char city[21];
char state[21];
char zip[11];
char phone[12];

// get all variables
cout << "Enter your name: ";
cin.get(name, 21);
cin.ignore(80,'\n');
cout << "Enter your address: ";
cin.get(address, 21);
cin.ignore(80,'\n');
cout << "Enter your city: ";
cin.get(city, 21);
cin.ignore(80,'\n');
cout << "Enter your state: ";
cin.get(state, 21);
cin.ignore(80,'\n');
cout << "Enter your zip: ";
cin.get(zip, 11);
cin.ignore(80,'\n');
cout << "Enter your phone number: ";
cin.get(phone, 12);
cin.ignore(80,'\n');

/***************************************
* output all variables in this format: *
* Name *
* Address *
* City, State, ZIP Code *
* Phone Number *
***************************************/

cout << name << '\n';
cout << address << '\n';
cout << city << ", " << state << ", " << zip << '\n';
cout << phone << '\n';

return 0;
}
KoOk is offline   Reply With Quote
Old 10-20-2001, 01:14 PM   #3
Member (12 bit)
 
Paul Victorey's Avatar
 
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
Re: C++ program won't work!

Quote:
Originally posted by raja
Here's my code:

For some reason, it won't work. Please help!! It compiles okay, but when I try and link it, I get this error message:

"personal info.obj : error LNK2005: _main already defined in string.obj
Debug/string.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe."

Please help.. my teacher is retarded and doesn't know a damn thing about C++!! Our book doesn't help, and the compiler we're using (Microsoft Visual C++ 6.0) doesn't tell me how to fix my "multiply defined symbols." Any advice would be greatly appreciated!!!
Wht this message means is that is trying to like this, as well as string.obj (which is the compiled version of string.cpp, which I'm assuming is another file in this project?) and it found two main() functions. Because main() is defined more than once, it can't link the program.

Remove main() from string.cpp and you should be fine.
__________________
Paul M. Victorey
------------------
I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk.
Paul Victorey is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:33 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2