CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2009
    Posts
    19

    [RESOLVED] Macro at beginning of file not found

    Hello all. I have a macro at the beginning of my source file, however, it cannot be found later in my source file... any ideas? I'm using the MinGW GCC compiler, though I don't think it would matter... Also, there are more uses of the macro in other methods, but I did not show them here

    The program here asks simple addition questions

    The file
    Code:
    #include <ctime>
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <cstdlib>
    #define RANDUPT0(u) (rand()&#37;((u)+1))
    using namespace std;
    
    int runAdditionSequence(int numQs, int maxval);
    
    int main(){
    	int qnumber, max;
    	string qnum, maxnum, type;
    	cout<<"Welcome to the Math Quizzer."<<endl;
    	cout<<"How many questions do you want to be asked?"<<endl;
    	cin>>qnum;
    	stringstream(qnum)>>qnumber;
    	cout<<"What should the largest possible number be?"<<endl;
    	cin>>maxnum;
    	stringstream(maxnum)>>max;
    	runAdditionSequence(qnumber, max);
    	return 0;
    }
    
    int runAdditionSequence(int numOfQs, int maxValue){
    	int score;
    	srand((unsigned) time(0));
    	for(int i=1; i<=numOfQs; i++){
    		int num1 = RANDUPTO(maxValue), num2 = RANDUPTO(maxValue), ans;
    		string ansString;
    		cout<<i<<") "<<num1<<" + "<<num2<<" = ";
    		cin>>ansString;
    		cout<<endl;
    		stringstream(ansString)>>ans;
    		if(ans==(num1+num2)){
    			score +=1;
    		}
    	}
    	cout<<endl<<"Score: "<<score<<"/"<<numOfQs;
    	return score;
    }
    And the error message...
    Code:
    ..\src\Quizzer.cpp: In function `int runAdditionSequence(int, int)':
    ..\src\Quizzer.cpp:46: error: `RANDUPTO' was not declared in this scope
    Please do not criticize my code... I know it's not great, but I don't feel like fixing it right now...
    I do realize just writing a function instead of the macro would solve my problem, but I would like what I'm doing wrong.

  2. #2
    Join Date
    Aug 2007
    Posts
    858

    Re: Macro at beginning of file not found

    RANDUPT0 vs RANDUPTO. Look very closely at the last character in those.

    And yes, in a C++ program something like this should be in a inline function.

  3. #3
    Join Date
    May 2009
    Posts
    19

    Re: Macro at beginning of file not found

    *Emits self-humoring laugh*

    No wonder I had no idea. Must be tired...

    And here I was thinking it had something to do with me using arguments for the macro. (or whatever they are called.

  4. #4
    Join Date
    Oct 2008
    Location
    Singapore
    Posts
    195

    Re: [RESOLVED] Macro at beginning of file not found

    Your definition of the macro has '0' (zero) instead of 'O'.

  5. #5
    Join Date
    May 2009
    Posts
    19

    Re: [RESOLVED] Macro at beginning of file not found

    Yeah... this will bug me for ages...

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