i am taking my first C++ class and i can not clear the following error can anyone help

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


//christine gershen
// Exercise 4.17: Encryption.cpp
// Encrypts data given by user.
#include <iostream> // required to perform C++ stream I/O
#include <iomanip> // required to perform setprecision stream manipulator

using namespace std; // for accessing C++ Standard Library members


int main(); // function main begins program execution
{
int main=0;
int digit_one; //store digit one
int digit_two; //store digit two
int digit_three; //store digit three
int digit_four; //store digit four

cout <<"Enter four-digit number:"; //asking the user to enter four-digit number

cin >> main; //four-digit number

digit_one=main%10; // digit_one is first four-digit number

digit_two=main/10%10; // digit_two is second four-digit number

digit_three=main/100%10; //digit_three is third four-digit number

digit_four=main/1000%10; //digit_four is fourth four-digit number

digit_one=(digit_one + 7%10); //add digit_one to 7 and mod 10

digit_two=(digit_two + 7%10); //add digit_two to 7 and mod 10

digit_three=(digit_three + 7%10); //add digit_three to 7 and mod 10

digit_four=(digit_four + 7%10); //add digit_four to 7 and mod 10

cout <<"Encrypted digits:"; << digit_three; digit_four; digit_one; digit_two; << endl;// display encrypted numbers


return 0; // indicate that program ended successfully

}; // end function main


/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/

Recommended Answers

All 6 Replies

int main();

remove the semi column

cout <<"Encrypted digits:"; << digit_three; digit_four; digit_one; digit_two; << endl;// display encrypted numbers

fix this as well, its a good practice not to have functions and variables with same name.

int main();

remove the semi column

That worked but now i am getting

cpp(40) : error C2143: syntax error : missing ';' before '<<'
cpp(40) : error C2143: syntax error : missing ';' before '<<'

int main(); // function main begins program execution
{
int main=0; 
int digit_one; //store digit one
int digit_two; //store digit two
int digit_three; //store digit three
int digit_four; //store digit four

Lose the semi-colon after main() on Line 1. Having it there changes it from a function header to a function prototype, then it doesn't know what to do with the brace(s).

Also, Line 3 is technically legal, but it's a VERY bad idea. It would be advisable to change that variable's name to something else.

edit youre code by placing it into code tags.

}; // end function main

remove semi column, In the future just go to the line of code where the error is and see if you can spot it.

thank you fixed it

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.