Thread: C programming question on Conditional Expressions!

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    1

    C programming question on Conditional Expressions!

    Hey guys I am new in learning C and I am kinda confused with this problem here, write an if statement that will assign the value 1 to the variable best if the integer variable score is 90 or greater.. However I am supposed to rewrite the program and use a conditional expression instead.. anyone that could just give me any pointers please? would be much appreciated! - n00brammer

  2. #2
    Registered User Ktulu's Avatar
    Join Date
    Oct 2006
    Posts
    107
    best = score >= 90 ? 1 : 0;

    The 'score >= 90' part will be the condition, when this condition is true take the value whatever comes after ?, if it is not true then take the value whatever comes after :.

    The ?: operator is called ternary conditional.
    Last edited by Ktulu; 09-20-2015 at 11:58 PM.
    This parameter is reserved

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about conditional operators ( || vs |)
    By patishi in forum C Programming
    Replies: 2
    Last Post: 10-06-2013, 04:25 AM
  2. Replies: 15
    Last Post: 07-17-2012, 01:35 AM
  3. Regular expressions question
    By Devils Child in forum C# Programming
    Replies: 7
    Last Post: 08-21-2009, 01:18 PM
  4. Conditional Compile Question
    By nobbyv in forum C Programming
    Replies: 1
    Last Post: 12-05-2005, 10:19 AM
  5. Using Conditional Expressions.
    By PLC in forum C Programming
    Replies: 1
    Last Post: 09-17-2003, 08:09 AM