CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011
    Posts
    9

    Exclamation class Timer error message :O

    I keep getting this error whenever I compile my program. I am using XCode and am not sure of what to do or how to fix this error.
    Code:
    #define TIMER_H_DEF
    #include <iostream>
    #include <string>
    #include <sys/time.h>
    int main ()
    class Timer // <----- Error: Expected initializer before 'class'
    {
    public:
    	timer();
    	~Timer();
    	using std::cout;
    	using std::cin;
    	using std::string;
    	int enter, gold, number, america, newgold;
    	int twogold, city, threegold, passcode;
    // Beginning of game.
    cout << "Welcome to the coin game. "
    << "The objective is to get 1000 coins by the end.\n"
    	<< "\nNow please create a random 8 number passcode "
    	<< "using ONLY numbers.\n";
    
    	cin >> enter;
    	
    	while (enter <= 10000000 || enter >= 99999999 ) {
    		cout << "\nYour passcode is less than 8 digits "
    		<< "(do not use 0 as the first digit).\n";
    		
    		cout << "Please try again.\n";
    		cin >> enter;
    	}
    
    cout << "\nFirst, solve 432 * 23, "
    << "in order to get your first 50 coins "
    << "(no calculators!).\n";
    	timer.start();
    	cin >> number;
    	timer.stop();
    	
    	cout << "You took "
    	<< timer.getElapsedTimeInMilliSec
    	<< " ms "
    	<< "to solve the equation.";
    This is not the entire program so don't worry if you don't see a return 0 or anything.

  2. #2
    Join Date
    Oct 2010
    Posts
    60

    Re: class Timer error message :O

    Your class definition cannot be inside a method. Have it outside the main() function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured