473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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

93 64KB
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. "Redefinition 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 6693
Nepomuk
3,112 Expert 2GB
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 "LoopsCppTutorial.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 64KB
yes, the "#include "LoopsCppTutorial.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 Expert Mod 8TB
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 64KB
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 Expert Mod 8TB
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 64KB
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
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...
2
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 ...
5
by: Bob Rundle | last post by:
I heard that managed C++ in VS 2005 supports multiple inheritence. Is this true? Bob Rundle
3
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
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...
6
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...
5
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...
6
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...
1
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
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,...

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.