Sign in to follow this  
brandonman

error in devC++

Recommended Posts

I'm writing a game in C++ and keep getting the error: 3 C:\Dev-Cpp\textgame.cpp expected unqualified-id before '{' token ; here's source:{ printf("welcome, type your name:") scanf("%s",&n); printf("hello %s") } please find the error: this is the greeting for the game, once I solve this, I'll work on the rest.

Share this post


Link to post
Share on other sites
A) you need to post all the code
B) printf("welcome, type your name:") should be printf("welcome, type your name:"); and printf("hello %s") should be printf("hello %s");, you end function calls with a semicolon!

Share this post


Link to post
Share on other sites
Hey Brandon,

That source code there isn't complete. You're missing out int main()!

You're also missing out any #include statements that may be needed. Finally, you need to return 0 at the end of int main() (although some compilers add this in for you).

C++ takes advantage of better ways for text I/O. Instead of using printf() I recommend you use std::cout and instead of using scanf() I recommend you use std::cin. The functions printf() and scanf() are generally used in C rather than C++.

Best of luck to you :-).

Share this post


Link to post
Share on other sites
Brandon I recommend you read some tutorials for getting started in C++ programming.

Cprogramming has a fantastic beginners tutorial with quizes to help you understand your own code aswell as learn new things!

Try this:

#include <cstdio>

int main() {
char* n;

printf("welcome, type your name:");
scanf("%s",&n);
printf("hello %s", &n);
}



Please not that this is a C program and NOT a C++ program.

Share this post


Link to post
Share on other sites
Thank You!!!! Now, I need to get the if statement done to get it working.
gonna check the help menu in dev-C++ which is where I'm programming this.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this