not able to compile the simplest code i.e. of hello world
the code is
the error wasCode:#include<iostream>
using namespace std;
int main()
{
cout<<"hello world!!!";
return 0;
}
collect2.exe: error: ld returned 1 exit status
Printable View
not able to compile the simplest code i.e. of hello world
the code is
the error wasCode:#include<iostream>
using namespace std;
int main()
{
cout<<"hello world!!!";
return 0;
}
collect2.exe: error: ld returned 1 exit status
So what kind of errors are you getting?
What compiler are you trying to use?
When you downloaded the IDE did you also download a compiler?
Jim
i m using DEV C++ editor which comes with MinGW GCC 4.7.2 32-bit compiler
i actually was making a game something like a tournament in which we fight different people and then upgrade ourselves after each fight but its still incomplete
and we can have test run
but when i run it i face only one error i.e.
collect2.exe: error: ld returned 1 exit status
and also when i use borland C++ compiler then i face no errors
then i made a simple program of hello world and i still got same error in DEV C++!!!
Code:#include<iostream>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#include<stdio.h>
#include<dos.h>
using namespace std;
struct player{
int health,armour,damage[2],money;
char name[10];
}p;
struct rat{
int health,armour,damage[2],money;
}rat1;
int main();
void tutorial();
void options();
void shop();
void quit();
void weapons();
void armour();
void extras();
void start(void)
{
system("cls");
cout<<"when you are ready press enter...";
getch();
}
void tutorial(void)
{
system("cls");
cout<<"learn how to play this game...\npress any key to continue.";
getch();
cout<<"dsfsfw";
}
void options(void)
{
system("cls");
}
void shop()
{
back:
int b=1;
system("cls");
cout<<"\nwelcome to the shop";
cout<<"press...\n (1) to buy weapons\n (2) to buy armour\n (3) to buy extras\n (4) back";
char a=getch();
switch(a)
{
case '1':weapons();break;
case '2':armour();break;
case '3':extras();break;
case '4':b=0;break;
}
if(b)
{
system("cls");
goto back;
}
}
void weapons()
{
cout<<"choose...\n(1) light weapons \n(2) medium weapons\n(3) heavy weapons";
int a;
cin>>a;
switch(a)
{
case 1:{
cout<<"light weapons press...\n (1) small stick (cost 10 damage : 0-3)\n (2) twig (cost 15 damage : 2-5)\n (3) sharp bamboo spear (cost 20 damage : 5-10)\n (4) rusty sword (cost 30 damage : 10-20)\n (5) iron sword (cost 40 damage : 15-25)";
cin>>a;
switch(a)
{
case 1:{
p.damage[0]=0;
p.damage[1]=3;
p.money-=10;
}break;
case 2:{
p.damage[0]=2;
p.damage[1]=5;
p.money-=15;
}break;
case 3:{
p.damage[0]=5;
p.damage[1]=10;
p.money-=20;
}break;
case 4:{
p.damage[0]=10;
p.damage[1]=20;
p.money-=30;
}break;
case 5:{
p.damage[0]=15;
p.damage[1]=25;
p.money-=40;
}break;
case 6:system("cls");break;
}
}break;
case 2:
{
cout<<"\nmedium weapons press...\n (1) medium sword (cost 50 damage : 20-30)\n (2) medium iron sword(cost 60 damage : 20-35)\n (3) sharp sword(cost 80 damage : 40-60)\n (4) sharp long sword (cost 100 damage : 50-100)\n (5) double sword(cost 120 damage : 60-100)\n (6) back";
cin>>a;
switch(a)
{
case 1:{
p.damage[0]=20;
p.damage[1]=30;
p.money-=50;
}break;
case 2:{
p.damage[0]=20;
p.damage[1]=35;
p.money-=60;
}break;
case 3:{
p.damage[0]=40;
p.damage[1]=60;
p.money-=80;
}break;
case 4:{
p.damage[0]=50;
p.damage[1]=100;
p.money-=100;
}break;
case 5:{
p.damage[0]=60;
p.damage[1]=100;
p.money-=120;
}break;
case 6:system("cls");break;
}
}break;
case 3:
{
cout<<"heavy weapons press...\n (12) silver sword (cost 125 damage : 65-100)\n (13) golden sword(cost 150 damage : 80-120)\n (3) diamond tipped sword(cost 180 damage : 100-200)\n (4) diamond sword (cost 200 damage : 150-250)\n (5) the sword of death(cost 300 damage : 500-600)\n (6) back";
cin>>a;
switch(a)
{
case 1:{
p.damage[0]=65;
p.damage[1]=100;
p.money-=125;
}break;
case 2:{
p.damage[0]=80;
p.damage[1]=120;
p.money-=150;
}break;
case 3:{
p.damage[0]=100;
p.damage[1]=200;
p.money-=180;
}break;
case 4:{
p.damage[0]=150;
p.damage[1]=250;
p.money-=200;
}break;
case 5:{
p.damage[0]=500;
p.damage[1]=600;
p.money-=300;
}break;
case 6:system("cls");break;
}
}break;
}
}
void quit(void)
{
system("cls");
}
void back()
{
system("cls");
}
int main()
{
system("cls");
char a;
cout<<"welcome to 'the tournament'\n";
cout<<"press...\n (1) to start\n (2) for tutorial\n (3) for options\n (4) to quit";
a=getch();
switch(a)
{
case '1':start();break;
case '2':tutorial();break;
case '3':options();break;
case '4':quit();break;
}
return 0;
}
Verify: (1) the source file is properly included in the project, and (2) the source file has the correct file extension.
Also what is this?
The function main() doesn't need a prototype.Code:
int main();
Where did you implement your armour() and extras() functions?
Why are you including the <dos.h> header file? It's a "little" outdated and shouldn't really be used with today's modern operating systems.
Also if you're writing a C++ program you should be using the C++ standard headers not their C versions, <cstdio> instead of <stdio.h>. And since you're not actually using anything in these C headers you shouldn't be including them anyway.
Jim
i already explained that this is incomplete executable code fragment also i need these standard library functions because i know only this much and still learning + i feel an ease to use these function
i will use the function delay(double) from the header file dos.h
and about the prototyping of main function i need that in the function ask() where i will ask the user to rerun this code if yes then i'll call the function main()
also i face no errors in borland C++ editor!!!
till i get the solution i'll continue my work in borland C++ editor
Here's some extra punctuation of mine that you can have to make your messages more clear:
......,,,,,,
You shouldn't be calling main from another function. Instead, you should have a loop in main that cycles or breaks based on the return value of "ask()".
As to the problem at hand, did you check the things I mentioned in post #4?
It is not permitted to use the global main function in your program. Therefore, you are not allowed to call it. Luckily, there is an alternative: have the main function call the function (possibly indirectly) in a loop instead.Quote:
Originally Posted by Mukul Kumar
Since this is a C++ program this doesn't make any sense. In a C++ program main() can't be called by any function, including main(). And even in a C program calling main() is considered a very very bad practice.Quote:
and about the prototyping of main function i need that in the function ask() where i will ask the user to rerun this code if yes then i'll call the function main()
So then what is your problem? Incomplete code fragments rarely compile if you haven't at least implemented "stub" functions (functions with blank bodies).Quote:
i already explained that this is incomplete code fragment
Jim
see the problem is ......that i was verifying time and again to check the working of the code properly and suddenly i faced this problem hence i say it is 100% executable(i tried this in turbo C++) and I AM WORKING ON THOSE FUNCTIONS HAVING NOTHING!!!
thanks i will take care of this in future @laserlight,matticus&jimblumberg about that calling of main()
now i may not reply for 20 hrs because this is the time in one day when i sit on computer and work + its 10:23 PM here in my country and i m gonna goto sleep so good-night!!!
i promise i'll work hard on this code:):):)
Borland C++ and Turbo C++ are both garbage. They do not support the standard C++ language. Don't ever use them.
Don't use these headers, as they are not standard, and almost certainly will not work in Dev C++. this goes for the getch() function as well.
Don't use goto. it is incredibly bad practice, and you can use a simple while loop to do what you're trying to do here.
i found the problem its not in my incomplete code,not even in my bad habits it was in my editor my naughty bro disturbed some settings(i don't know which one) and i set everything to default by reinstalling the editor but thanks to all of you for telling me about my bad habits i'll take care :D