LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2004, 07:21 PM   #1
shams
Member
 
Registered: Jan 2004
Posts: 535

Rep: Reputation: 30
Unhappy problem coding conditional operators


hi,
this is the code to be changed to conditional operators:
#include <stdio.h>
main()
{
int code;
printf("Enter the coem number\n");
scanf("%d",&code);
if(code>1)
printf(\njerusalem");
else
{
if(code<1)
printf("\nEddie");
else
printf("\nBrain");
}

}


the above code is runing without any error but the problem is when it is changed to conditional operators:

#include <stdio.h>
main()
{
int code;
printf("Enter value for code\n");
scanf("%d\n",&code);

(code>1 ? printf("\njerusalim\n") : (code<1 ? printf("\nEddie\n") : printf("Brain\n")));

}

then with:
$gcc -o lb70 lb70.c
there is no error but now when i am runing this ./lb70 it is asking for the input then there is no output and when i hit <return>it is halting without any ouput as shown below:
[root@localhost lbin]# ./lb70
[root@localhost lbin]# ./lb70
Enter value for code
2



plz help me.
 
Old 07-13-2004, 07:39 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
It might be better to move your printf() outside. Something like this:
Code:
printf("\n%s\n", code>1?"jerusalim":code>1?"Eddie":"Brain");
You should also get rid of the \n in your scanf() format string. I tested the code I just showed and it works fine.

Last edited by itsme86; 07-13-2004 at 07:42 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
coding problem on php auto send mail after a period akamaru607 Programming 12 09-01-2005 07:48 AM
Operators *^ and >> GodSendDeath Programming 4 11-01-2004 09:47 PM
about bitwise operators? eshwar_ind Programming 17 10-25-2004 02:13 AM
problem coding odd loop shams Programming 3 07-17-2004 01:22 PM
operators linuxanswer Programming 3 12-14-2003 06:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration