Archived

This topic is now archived and is closed to further replies.

MPG

stupid error;is vc++ haunted?..?

Recommended Posts

heres the code:
#include <iostream>
#include <conio.h>

int main(){
int x;
int y;
void add();
{
	;std::cout<<"x+y";std::endl
		;}


;std::cout<<"welcome to calc +!!";std::endl
;std::cin>>x,y;
add()

;getch();

	return 0;

	;}
 
error: c:\Documents and Settings\Randle\My Documents\Visual Studio Projects\done\over.cpp(10): error C2568: ''identifier'' : unable to resolve function overload line 10 ___________________________ p.s i know some people think i can man an MMORPG with a blind fold on and a headach... but can someone help

Share this post


Link to post
Share on other sites
dont use std
use something like scanf or getc
bug is the comma:
std::cin>>x,y; -> std::cin>>x; std::cin>>y;

also the semicolon after declaration of add()

quote:

Dick's Lemma:
"Just because you`re paranoid doesn`t mean they`re not out to get you."

The Programmer's dilemma:
"Programming is like sex: One mistake and you're providing
support for a lifetime."



[edited by - caesar4 on January 17, 2004 12:33:16 PM]

Share this post


Link to post
Share on other sites
C++ does not support local function definitions. You need to move your add() function out of the scope of main to namespace scope, and alter it so that it takes parameters.

Share this post


Link to post
Share on other sites
quote:
Original post by MPG
are you syaing make the funtion first then iint maiin{ or

{
add()
}


Add ofcourse...

Do it like this instead ffs:

#include <iostream>

void add(int x, int y)
{
std::cout << x+y << std::endl;
}


int main()
{
int x;
int y;


std::cout << "Welcome to calc+!" << std::endl;
std::cin >> x,y;
add(x, y);

int mu;cin>>mu;
return 0;
}

Share this post


Link to post
Share on other sites
You have to put semi-colons after your statements. Most of that should work, but doing it that way is very error-prone. Do this:

int main()
{
cout<<"Hi!\n";
cout<<"Welcome to calc\n";
return 0;
}

not this:

int main()
{
// note the semi-colon before cout<<"Hi!\n" is not necesarry
// as there is no statement before that
;cout<<"Hi!\n"
;cout<<"Welcome to calc\n"
;return 0;
}

And why are you declaring a function in int main!? You don't put semi-colons after you declare a function. std::cout<<"x+y" will output the string "x+y", not the value of x+y. std::endl can't be put on it's own line (like any other c++ class or struct or variable for that matter). You should output endl. eg:
std::cout<<x+y<<std::endl;

edit:
Also, reread (or just read) a C++ book. I don't know where you picked up that coding style, but it's horrendous. Most of it's not even valid C++.

[edited by - brassfish89 on January 17, 2004 1:21:04 PM]

Share this post


Link to post
Share on other sites
When I put in somthing wrong VC++ .NET ERRORS tell me to put the semi-colons in... thats why I say it haunted

I have a new error
code
voidadd(int x,int y);
{
;std::cout<<"x+y";std::endl
}

error
c:\Documents and Settings\Randle\My Documents\Visual Studio Projects\done\over.cpp(4): error C2447: ''{'' : missing function header (old-style formal list?)


thx for not flaming me

Share this post


Link to post
Share on other sites
OK its been said 1000000000000000000000 times YOU PUT SEMICOLONS IN THE WRONG PLACE!

//notice no space there

void add(int x,int y) //no semicolon after void

{
//no semicolon BEFORE funtions

std::cout<<x+y<<std::endl;
}


[Mercury Software] [Google!] [ Look I DONT Follow Trends ]

[edited by - DerAngeD on January 17, 2004 1:44:52 PM]

Share this post


Link to post
Share on other sites
Semi-colons do not go at the end of a function header, and do go at the ends of statements:


void add (int blah) // No semi-colon there!

{
std::cout << blah << std::endl; // semi-colon there

}


If you still don''t get it, you really need to buy and read a book on C++...

-Auron

Share this post


Link to post
Share on other sites
if i do that it gives me
c:\Documents and Settings\Randle\My Documents\Visual Studio Projects\done\over.cpp(4): error C2447: ''{'' : missing function header (old-style formal list?)

again

Share this post


Link to post
Share on other sites
Let''s face it. If you''re not just trolling, you need to re-learn C++ from scratch, because right now you have absolutely no idea what you''re doing. Get a book, because there''s no way you can learn C++ by asking us to fix your horribly mangled code again and again.

Share this post


Link to post
Share on other sites
Click here.

PS: When it says that you need to put semicolons, it can (especially in this program...) mean that that code shouldn't be there at all!

PPS: I don't mean to flame, just trying to make the link stand out more than the rest of this mumble-jumble (no offense).

[edited by - jtmerchant on January 17, 2004 2:34:32 PM]

Share this post


Link to post
Share on other sites