• Advertisement
Sign in to follow this  

error in devC++

This topic is 4326 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Thank you. This is the whole thing though-I only have the greeting ready, working on finding I/O in the help menu for it.

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

This topic is 4326 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement