473,581 Members | 2,304 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 6739
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
1797
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...
2
4698
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
1425
by: Bob Rundle | last post by:
I heard that managed C++ in VS 2005 supports multiple inheritence. Is this true? Bob Rundle
3
1870
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
1515
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
1630
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
1692
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...
6
2203
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
4059
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...
8
2885
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...
0
7862
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...
0
7789
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...
0
8301
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8169
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...
0
6551
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...
0
5361
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...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.