473,909 Members | 4,189 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple "int Main()" errors(NEED HELP!)

93 New Member
Now I'm learning while coding so to speak and I have an error I haven't got any idea on how to fix. The file is basicly a documantary of what I learn and how I picture it in my head, so if I forget, I can go back and look...

My errors:

1. "In function `int main()':"

2. "Redefiniti on of `int main()'" (I know that it sets
the value of Main again, but how can I fix it?)

3. "`int main()' previously defined here" (same as #2
but how can I fix it?)

My Code:
Expand|Select|Wrap|Line Numbers
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. #ifndef _AndOrStatement_cpp_
  5. #define _AndOrStatement_cpp_
  6.  
  7. #include "LoopsCppTutorial.cpp"
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     //Press "Compile & Run" to see what they output
  14.  
  15.     cout << "NOT: " << endl;
  16.  
  17.     //This equals 1 = false
  18.     double var9;
  19.     if (1 != 0)
  20.     {
  21.         var9 = true;
  22.         cout << var9 << endl;
  23.     }
  24.     else
  25.     {
  26.         var9 = false;
  27.         cout << var9 << endl;
  28.     };
  29.  
  30.     //__________________________________________________________
  31.  
  32.     cout << "AND: " << endl;
  33.  
  34.     //This equals 0 = true
  35.     double var;
  36.     if (0&&0) 
  37.     {
  38.         var = true;
  39.         cout << var << endl;
  40.     }
  41.     else 
  42.     {
  43.         var = false;
  44.         cout << var << endl;
  45.     };
  46.  
  47.     //__________________________________________________________
  48.  
  49.     //This equals 1 = false
  50.     double var2;
  51.     if (1&&1) 
  52.     {
  53.         var2 = true;
  54.         cout << var2 << endl;
  55.     }
  56.     else 
  57.     {
  58.         var2 = false;
  59.         cout << var2 << endl;
  60.     };
  61.  
  62.     //__________________________________________________________
  63.  
  64.     //This equals 0 = true
  65.     double var3;
  66.     if (1&&0) 
  67.     {
  68.         var3 = true;
  69.         cout << var3 << endl;
  70.     }
  71.     else 
  72.     {
  73.         var3 = false;
  74.         cout << var3 << endl;
  75.     };
  76.  
  77.     //__________________________________________________________
  78.  
  79.     //This equals 0 = true
  80.     double var4;
  81.     if (0&&1) 
  82.     {
  83.         var4 = true;
  84.         cout << var4 << endl;
  85.     }
  86.     else 
  87.     {
  88.         var4 = false;
  89.         cout << var4 << endl;
  90.     };
  91.  
  92.     //__________________________________________________________
  93.  
  94.     cout << "OR: " << endl;
  95.     //This equals 0 = true
  96.     double var5;
  97.     if (0||0)
  98.     {
  99.         var5 = true;
  100.         cout << var5 << endl;
  101.     }
  102.     else
  103.     {
  104.         var5 = false;
  105.         cout << var5 << endl;
  106.     };
  107.  
  108.     //__________________________________________________________
  109.  
  110.     //This equals 1 = false
  111.     double var6;
  112.     if (1||1)
  113.     {
  114.         var6 = true;
  115.         cout << var6 << endl;
  116.     }
  117.     else
  118.     {
  119.         var6 = false;
  120.         cout << var6 << endl;
  121.     };
  122.  
  123.     //__________________________________________________________
  124.  
  125.     //This equals 1 = false
  126.     double var7;
  127.     if (0||1)
  128.     {
  129.         var7 = true;
  130.         cout << var7 << endl;
  131.     }
  132.     else
  133.     {
  134.         var7 = false;
  135.         cout << var7 << endl;
  136.     };
  137.  
  138.     //__________________________________________________________
  139.  
  140.     //This equals 1 = false
  141.     double var8;
  142.     if (1||0)
  143.     {
  144.         var8 = true;
  145.         cout << var8 << endl;
  146.     }
  147.     else
  148.     {
  149.         var8 = false;
  150.         cout << var8 << endl;
  151.     };
  152.  
  153.     //__________________________________________________________
  154.  
  155.     system("PAUSE");
  156.     return EXIT_SUCCESS;
  157. }
  158.  
  159. #endif
  160.  
This is a "Console Application" written in Dev-C++

X(sorry for bad english, I'm norwegian and that can explain a lot... )
Jul 4 '13 #1
6 6776
Nepomuk
3,112 Recognized Expert Specialist
The code you've written looks fine, but in line 7 you include another file:
Expand|Select|Wrap|Line Numbers
  1. #include "LoopsCppTutorial.cpp"
If you remove that like, the code works without any problems. So I'm guessing that "LoopsCppTutori al.cpp" includes a main method?

One way to solve all of this would be to split your learning project further. Have you learned about header files and prototypes yet? If so, you could have a header file for this and every other step you take and none of your cpp files contain main methods. (Just call them something different.) Then you create one Main.cpp which would look something like this:
Expand|Select|Wrap|Line Numbers
  1. #include "step1.h"
  2. #include "step2.h"
  3. #include "step3.h"
  4.  
  5. int main() {
  6.    // The main method from step 1 is now called "step1()":
  7.    step1();
  8.    // Similarly for step 2:
  9.    step2();
  10.    // And of course for step 3:
  11.    step3();
  12.    return 0;
  13. }
  14.  
Now when you compile your project it would have to include the other cpp files too. I'm not sure how Dev-C++ solves this (it might be automatic) but with g++ I would do something like this:
Expand|Select|Wrap|Line Numbers
  1. g++ Main.cpp step1.cpp step2.cpp step3.cpp
Jul 4 '13 #2
Xillez
93 New Member
yes, the "#include "LoopsCppTutori al.cpp"" includes a main method and that is the problem?

ok, and no I haven't learned about hearder files(I know why they are there and maybe what their task are but haven't learned the language so I can't write one... )

I know the code works without the #include thing because I used the "Compile & Run" option, but do I really need a header file? and if so how am I supposed to write it...
Jul 5 '13 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
First, you never include code. That is, you never include anything that will occupy memory. As you can see, you get multiple definition errors.

Second, you don't need header files.

However, if you need to call a function in several.cpp files, you can't have the code in each file so you write the code once in one file and in the other files you insert the first line of the function followed by a semi-colon. This is a "function prototype" and it tells the compiler not to worry if the function you call is not defined (has no code) in this file.

If your program has 500 files, you will need to have this prototype in 499 files. If you change the function so that the first line is different, you have changed the prototype. So you need to make 499 other changes.---OR you have the prototype in one file that you #include in the other 499. This way you make your change once and rebuild your program.

A header file, then, is just a text file like your source code files. There's no particular magic in the name of the file. C uses .h extensions historically while C++ does not.
Jul 5 '13 #4
Xillez
93 New Member
ok, so I need to learn how to write the header files/learn how to join two or more files together?
Jul 5 '13 #5
weaknessforcats
9,208 Recognized Expert Moderator Expert
Yes you do.

The process involves a makefile which contains info on the files to compile, instructions to the linker for combining all of the object files t make your .exe.

Depending upon your IDE, the makefile may be generated for you when you click build on a project.

The make utility reads the makefile and launches the various processes. This is the build.
Jul 5 '13 #6
Xillez
93 New Member
ok, I'll get right on it... thanks for the help...

X
Jul 5 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1805
by: armitageshanks | last post by:
Hi, Hopefully this is a fairly simple question. I currently have a database that has several tables on it. Displayed in user friendly forms. On one of the forms is an entry that records videos received by an outside party. The person using the form then enters the amount of videos received in a box. My question is, after the amount has been entered I want to be able to create an amount of entries in relation to that figure. Example: If 6...
2
4710
by: zeke | last post by:
Any assistance is much appreciated... I have a table with duplicate record information and I need to remove certain records based on values in four different fields. For example: PK field Name Date1 Date2 Date3 1 Bill 1/21/04 1/18/02 5/14/04 2 Bill 1/15/03 1/18/02 5/14/04 3 Bill 1/25/04 5/14/04
5
1439
by: Bob Rundle | last post by:
I heard that managed C++ in VS 2005 supports multiple inheritence. Is this true? Bob Rundle
3
1892
by: JFB | last post by:
Hi All, It's a way to upload multiple files on a web site using vb.net 2005? I see the uploadFile tool, but it's only for one file. Any ideas, examples, links??? Tks in advance JFB
0
1536
spider1916
by: spider1916 | last post by:
hi there, i need some help on hou to add multiple files selected in an ShowOpen dialog box to my listview. i am using my listview to display all the attached files for an email. i can add a single file at a time but need to add multiple files too. pls help.
6
1643
by: Marc | last post by:
Hi, I am using the below code which simply allows a single button control to be dragged and dropped anywhere around a form. My problem is that want to move about 100 buttons on the form. Is there anyway to modify the code so that any buttons added on the form will be able to be dragged and dropped? Many Thanks!
5
1707
werks
by: werks | last post by:
Hello experts. I have 2 vbp (namely Project1.vbp and Project2.vbp) I Group them into 1 Project, my problem is how can the user choose on what project they want to use using VB6? My initial idea is when the user login a form will prompt, and the user will be given a choice w/c project to run the Project1.vbp or the Project2.vbp.. Please help me on this. tnx in advance. -- Kenneth "Better Than Yesterday"
6
2220
by: OzairKhalid | last post by:
Hi, I have uploaded "ClientMultiSample2k.zip" at ... http://tech.groups.yahoo.com/group/MS_Access_Professionals/files/2_AssistanceNeeded/ClientMultiSample2k.zip The file is basically Allen Browne's sample. I have tried to get it customized for me. frmClient:
1
4074
by: craigcairley | last post by:
Hi guys and gals, I am trying to do a search of a table in my DB but one of the fields is CompanyID which links to another table that has all the company information so I don't have to write the company details every time into our contacts DB. However when I need to search all contacts (for example) if i need all customers in one company I do this SQL Query: SELECT...
8
2901
by: ViktorS | last post by:
Hello everybody, My VBA knowledge is pretty limited but I had to mock up the code and looking for proffesional input to correct it/improve it. My table "Sort_rpt" has a text field "Status Desc". I must standardize records in this field by removing/trimming data (text and numbers)and append it into another field "New_Status_Desc". Here is the part of the code I used. I have about 20 stqSQL statements. Problem with it- takes time to run it and...
0
10035
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9877
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,...
0
11346
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10538
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9725
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
8097
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
7248
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
5938
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.