Could my problems be because of the c++ version?

I do as ben defined but i had errors i copied ben code i still have alot of error i fixed it i dont know is it becz of c++ new version

#include<iostream>
#include<string>
using namespace std;



//entry point for over appliction
int main()
{
	

	
	void PrintIntro();
	{
		constexpr int World_Length = 9;

		cout << "Welcome to bulls and cows\n";
		cout << "Can you guess the" << World_Length;
		cout << " the letter isogram im thinking of ?\n";
		cout << endl;
		
	}

	string GetGuessAndPrintBack(); {
		//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;

		
	}
}

Hello there!

You have several problems with your code, that we will try to solve together.

  • When you define function/method, you should NOT put semicolon " ; " after it.
    You put semicolon just at the end of the statements that are inside curly brackets { }.

  • Your first function is “void PrintIntro ()”. Being void, it means that it does not expect you to return something.
    However, second function is called “string GetGuessAndPrintBack ()”, and because it’s type is string, you must return string (in your case string is string Guess).

  • The compiler ALWAYS expects you to have function “int main ()”.
    The functions “PrintIntro()” and “GetGuessAndPrintBack()” will not execute in the form useful to you, unless you call for them inside “int main ()” function!
    Imagine it as if those two functions are recepies, how to do something, that is then actually executed inside int main function.

      #include <iostream>
      #include <string>
    
      using namespace std;
    
      void PrintIntro () //No semicolon here!
      {
          constexpr int World_Length = 9;
    
          cout << "Welcome to bulls and cows\n";
          cout << "Can you guess the " << World_Length;
          cout << " the letter isogram im thinking of ?\n";
          cout << endl;
    
      }
    
      string GetGuessAndPrintBack()   // No semicolon here!
       {
          //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 statement, because your function requires it (it is not void)
          return Guess;
      }
    
    
      //you always have to have main function!
      int main ()
      {   
          //calling functions created above!
          PrintIntro();
          GetGuessAndPrintBack();
         
          return 0;
      }

Privacy & Terms