|
-
June 19th, 2009, 10:56 PM
#1
[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()%((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.
-
June 19th, 2009, 11:23 PM
#2
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.
-
June 19th, 2009, 11:29 PM
#3
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.
-
June 20th, 2009, 01:28 AM
#4
Re: [RESOLVED] Macro at beginning of file not found
Your definition of the macro has '0' (zero) instead of 'O'.
-
June 20th, 2009, 10:10 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|