i just received some help from zandiago it his help was great and i thank you. when i incorporated the info into my program i received an error when building the solution. it was only one error. it was

error C2447: '{' : missing function header (old-style formal list?)

the error was at {(in red) How do i fix that and could you please explain how you fix it. thank you. i really appreciate everyones help with my project. this is a great place to learn with the help of others. here is my program. any help or ideas is greatly appreciated

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main ()
;int playSomeGames();
{ //< here
    int num;
    int guess;
    bool done;
    int noOfGuesses=0;
    int ncount;
    int sum=0;
    int noofgamesplayed = 0;
    int avgNoOfGuesses; 
    noofgamesplayed++;

void playSomeGames( ) {
  int numGamesPlayed = 0;
  do {
    playAGame();
    numGamesPlayed++;
  } while ( again );
  cout << "You played " << numGamesPlayed << " games";
}

void playOneGame ( ) {
  int numGuesses = 0;
  do {

  } while ( numGuesses < 10 );
  cout << "You took " << numGuesses << " to guess";
}int main ( ) {
  playSomeGames();
  return 0;
}

void playSomeGames( ) {
  int numGamesPlayed = 0;
  do {
    playAGame();
    numGamesPlayed++;
  } while ( again );
  cout << "You played " << numGamesPlayed << " games";
}

void playOneGame ( ) {
  int numGuesses = 0;
  // generate a target value
  do {
    // prompt for guess etc
  } while ( numGuesses < 10 );
  cout << "You took " << numGuesses << " to guess";
}

 sum += noOfGuesses;
     avgNoOfGuesses=sum/noofgamesplayed;
    srand((unsigned)time(0))
    ;num = (rand() % 1000);
    done = false;
    while ((noOfGuesses < 10) && (!done))

    {
        cout << "Enter an integer greater"
            << " than or equal to 0 and "
            << "less than 1000: ";
        cin >> guess;
        cout << endl;
        noOfGuesses++;
        if (guess == num)
        {
            cout << "you guessed the correct "
                << "number." << endl;
            done = true;
        }
        else
            if (guess < num)
                cout << "Your guess is lower "
                << "than the number. \n"
                << "Guess again!" << endl;
            else
                cout << "Your guess is higher "
                << "than the number.\n"
                << "guess again!" << endl;
            cout <<"Total gueses equal " << noOfGuesses << endl;
            cout << "you played " << noofgamesplayed << " games";



    }
    return 0;
    }

Dani AI

Generated

The C2447 "missing function header (old-style formal list?)" means the compiler found an opening brace ({) that is not attached to a valid function signature. In practice that happens when a function signature is accidentally terminated (for example with a stray semicolon) or when code structure is broken by missing semicolons, unmatched braces, or by trying to define a function inside another function. The compiler reports the brace because it no longer parses the preceding text as a function header.

Common, practical fixes and checks:

  • Remove stray semicolons after function signatures. A prototype ends with a semicolon; a definition must not. Do not write a signature, put a semicolon, then immediately open a brace — that brace will be orphaned.
  • Ensure function definitions are at global scope. C++ does not allow nesting one function definition inside another.
  • Look for missing semicolons on the lines immediately before the reported {. A stray missing semicolon can change how the parser interprets the next {.
  • Check for duplicate or partial copies of the same function (multiple playSomeGames/playOneGame snippets in this thread). Define each function once and keep prototypes (if used) separate from definitions.
  • Fix obvious syntax errors such as a missing semicolon after a statement that calls srand(...) or other library calls. Those will often cause the reported error on the following {.

A short, reliable debugging workflow:

  1. Re-indent and enable compiler warnings. 2) Comment out large blocks until the error disappears, then reintroduce code bit by bit. 3) Pay special attention to the exact line given by the compiler and the one immediately above it. 4) Keep prototypes at the top, one clear main, and function bodies below.

As advised, avoid blindly pasting function bodies; start with a clean main that compiles, then add well-formed functions. Credit to @zandiago for the earlier help — follow that pattern but make sure signatures and braces are syntactically correct.

Recommended Answers

All 2 Replies

>>any help or ideas is greatly appreciated

Don't blindly copy and paste and expect the code to work. It sends a pretty loud message, that most people don't want to hear.

If you want to use functions, then use them, but don't just slap into your program somewhere.

For now, I suggest you remove everything that has to do with functions other than main(), redeclare your variables and make sure they are all initalized before you try to use them. Zandiago gave you a good example of how to do it.

Also, keep all posts having to do with the same assignment in one thread.

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.