|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (7 bit)
|
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!!! |
|
|
|
|
|
#2 |
|
Member (6 bit)
Join Date: Oct 2001
Location: Canada
Posts: 53
|
//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; } |
|
|
|
|
|
#3 | |
|
Member (12 bit)
Join Date: Mar 1999
Location: MN or WI
Posts: 3,017
|
Re: C++ program won't work!
Quote:
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. |
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|