Need help with C++

I need some help… I swear everything is right as I was following the udemy tutorial but obviously I missed something. If somebody else could get their eyes on it they might be able to find a problem. Help!

This is what I have:

#include
#include

using namespace std;

void printintro

std::string GetGuess

//The entry point for our application

int main()
{
PrintIntro();

	GetGuess();

	cout << endl;
return 0;

}

void PrintIntro(){
// Introduce the game
constexpr int WORLD_LENGTH = 5;
cout << “Welcome to Bulls and Cows, a fun word game.\n”;
cout << “Can you guess the " << WORLD_LENGTH;
cout << " letter word I am thinking of?\n”;
cout << endl;
return;
}

string GetGuess() {

// get a guess from the player
cout << "Enter your guess: ";
string Guess = "";
getline(cin, Guess);

// repeat the guess back to them
cout << "Your guess was: " << Guess << endl;
cout << endl;
return Guess;

}

I really appreciate it, thanks!

But what are the issues do you have with it?

So far from what you showed I can only see this:

Here you missing (); It should be void printIntro();

Earlier you declared your ‘printIntro()’ with first letter ‘p’ as lowercase, and here you call it in Upper case.

Your includes are empty, i suspect it is because you copied code badly. Could you please reformat it

1 Like

Thanks! I really appreciate it man. It just wont run or anything. I fixed the first two problems you mentioned.

Here is is now:

#include
#include

using namespace std;

void printintro();

std::string GetGuess

//The entry point for our application

int main()
{
printIntro();

	GetGuess();

	cout << endl;
return 0;

}

void PrintIntro(){
// Introduce the game
constexpr int WORLD_LENGTH = 5;
cout << “Welcome to Bulls and Cows, a fun word game.\n”;
cout << “Can you guess the " << WORLD_LENGTH;
cout << " letter word I am thinking of?\n”;
cout << endl;
return;
}

string GetGuess() {

// get a guess from the player
cout << "Enter your guess: ";
string Guess = "";
getline(cin, Guess);

// repeat the guess back to them
cout << "Your guess was: " << Guess << endl;
cout << endl;
return Guess;

}

Ok, it doesn’t run, but which kind of error does it report to you?

Line 8 needs a semicolon at the end
std::string GetGuess;
Also you have a function named ‘GetGuess’ at line 31 and you declare a string with the same name at line 8.
You need to rename your std::string GetGuess to something else to resolve conflict.
Or if you don’t use it, you can remove it

1 Like

It works! I seriously cant thank you enough man. I appreciate the help!

I am glad I could help.

Next time if you have troubles, don’t forget to also include reported errors :wink:

1 Like

I’ll make sure I do that. This is my first coding attempt and my first day on the forum, so I have a lot to learn. :stuck_out_tongue:

This is my first coding attempt and my first day on the forum, so I have a lot to learn

Welcome aboard! :slight_smile:

When it comes to popping your code into posts on the forum, its typically better to copy/paste the code, and save screenshots for errors in the editor(s). The forum does quite well at determining which bits of your post is code, but, to format it nicely, if you add ``` before the code block and after it, it will look awesome. It’s also really useful for those that help you as they can just copy/paste a chunk of it back to you in a reply :slight_smile:

Hope this helps and again, welcome to the community.


See also;

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms