0

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)
PLUS1+1

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

Thanks!
C++

3
Contributors
5
Replies
9
Views
13 Years
Discussion Span
Last Post by Ghost
0

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

0

Hi,
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
it
#define PLUS1(x) (x+1)
if any more problem feel free to mail me to brnprasad630@yahoo.co.in

with regards
prasad

0

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.

Thanks,
C++

0

I figured it out!!! The answers are:

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

and:

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

Thanks for your help anyway.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.