I need help solving two macro questions in C++.
They are:

Define a macro PANIC that expands to code that uses cout to print the word PANIC and then calls a function quit (with no arguments).

I think the answer is

#define PANIC;
cout <<quit();

but the compiler gives me errors.
My second question is:

Define a macro PLUS1 that accepts a value as a parameter and produces an expression representing 1 more than the value.

My wrong answer was

#define PLUS1 (x)

If you know the answer, please tell me - also explain how you got the answer.


ur first question is somewhat confusing. but i give my idea.

#define PANIC (cout<<"panic";quit();))

the second question answer is:

#define PLUS1(x) (x+1)

still if u have any queries. write me to bvvkrishna@rediffmail.com

That's incorrect. Can anybody else help?

the first questions answer is

#define PANIC cout<<"panic \n"<<quit()
you should not put ; (semicolan after a #define )
Now this will solve ur problem

For the second one the previous (Krishnas) answars has to work properly
#define PLUS1(x) (x+1)
if any more problem feel free to mail me to brnprasad630@yahoo.co.in

with regards

When I run the first problem through the compiler, I get the message:

Wrong code assigned to PANIC. Check the function calls and don't forget semicolons.

On the second question, I get the error message:

It seems that you are lacking parentheses around the parameter supplied.

When I put a space between PLUS1 and (x), this message appears:

Wrong code assigned to PLUS1. Please revise.

Please help.


I figured it out!!! The answers are:

#define PANIC cout<<"PANIC";quit();


#define PLUS1(x) ((x)+1)

Thanks for your help anyway.

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.