User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 397,818 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,622 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 1004 | Replies: 7
Reply
Join Date: Mar 2007
Posts: 1
Reputation: mohiuddin.shaik is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
mohiuddin.shaik mohiuddin.shaik is offline Offline
Newbie Poster

Solution Changing the meaning of IF else statement

  #1  
Mar 28th, 2007
main()
{
if( ? )
{
printf("welcome");
}
else
{
printf("to ieg");
}
}
-----------------------------------------------------------------------
Output should be
welcome to ieg


what should come in place of ' ? '
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Changing the meaning of IF else statement

  #2  
Mar 28th, 2007
any conditional statement that is either true or false. for example if you were asked to enter either 'Y' or 'N' (Yes or No) then the statement might read
if( answer == 'Y')
{
   // true statement
}
else
{
   // false statement
}
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Rep Power: 4
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Changing the meaning of IF else statement

  #3  
Mar 28th, 2007
Originally Posted by Ancient Dragon View Post
any conditional statement that is either true or false. for example if you were asked to enter either 'Y' or 'N' (Yes or No) then the statement might read
if( answer == 'Y')
{
   // true statement
}
else
{
   // false statement
}

Thisnk it's a trick question. May be you didn't read it fully..

@mohiuddin.shaik
It is allowed to write/change anything other than ? e.g. can I use a goto inside the if block?
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,643
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Changing the meaning of IF else statement

  #4  
Mar 28th, 2007
you are right -- I didn't read the expected outcome, which is impossible. There is no solution that will give that outcome.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Feb 2007
Location: Bangalore, India
Posts: 535
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Rep Power: 4
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: Changing the meaning of IF else statement

  #5  
Mar 28th, 2007
Originally Posted by Ancient Dragon View Post
you are right -- I didn't read the expected outcome, which is impossible. There is no solution that will give that outcome.

What abt GOTO LABEL?

  1. if ( true )
  2. {
  3. cout << "Hi" << endl ;
  4. goto ELSE_PART ;
  5. }
  6. else
  7. {
  8. ELSE_PART:
  9. cout << " There" << endl ;
  10. }

of course that's cheating but then teh question is not fair..
Last edited by thekashyap : Mar 28th, 2007 at 11:23 am.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,806
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 338
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Changing the meaning of IF else statement

  #6  
Mar 28th, 2007
You have just gone out to show one of the horrors of using the GOTO statement in C/C++...
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Dec 2005
Posts: 3,340
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 20
Solved Threads: 378
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: Changing the meaning of IF else statement

  #7  
Mar 28th, 2007
Seems simple enough
int main()
{
    if (!printf("welcome ")) {
        printf("welcome");
    } else {
        printf("to ieg");
    }
    return 0;
}
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Reply With Quote  
Join Date: Apr 2006
Location: Canada
Posts: 4,459
Reputation: John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light John A is a glorious beacon of light 
Rep Power: 15
Solved Threads: 268
Moderator
Staff Writer
Featured Blogger
John A's Avatar
John A John A is offline Offline
Vampirical Moderator

Re: Changing the meaning of IF else statement

  #8  
Mar 28th, 2007
Originally Posted by Salem View Post
Seems simple enough
int main()
{
    if (!printf("welcome ")) {
        printf("welcome");
    } else {
        printf("to ieg");
    }
    return 0;
}

Wow... Salem! You never fail to impress me... (I'd give you more rep if the system would let me )
tuxation.com - Linux articles, tutorials, and discussions
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 6:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC