I NEED HELP ---- REGARDING "IF" STATEMENT

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NewYorker
    New Member
    • Sep 2006
    • 13

    I NEED HELP ---- REGARDING "IF" STATEMENT

    Q1:
    Write an expression that evaluates to true if the value of the integer variable numberOfPrizes is divisible (with no remainder) by the integer variable numberOfPartici pants . (Assume that numberOfPartici pants is not zero.)

    Q2:

    Write an expression that evaluates to true if the value of the integer variable widthOfBox is not divisible (with a remainder) by the integer variable widthOfBook . (Assume that widthOfBook is not zero.)

    Thanks pals.
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    Suppose numberOfPrizes = A*numberOfParti cipants+R.

    R = (numberOfPrizes % numberOfPartici pants);
    % is the modulo operation. Similarly for WidthOfWhatever .

    Use the modulo operation and test if it is 0.

    If J divides K, then ((J%K)==0).

    Comment

    • m013690
      New Member
      • Sep 2006
      • 23

      #3
      Originally posted by NewYorker
      Q1:
      Write an expression that evaluates to true if the value of the integer variable numberOfPrizes is divisible (with no remainder) by the integer variable numberOfPartici pants . (Assume that numberOfPartici pants is not zero.)

      Q2:

      Write an expression that evaluates to true if the value of the integer variable widthOfBox is not divisible (with a remainder) by the integer variable widthOfBook . (Assume that widthOfBook is not zero.)

      Thanks pals.
      Q1: ( numberOfPrizes % numberOfPartici pants == 0 );

      Q2: ( widthOfBox % widthOfBook != 0 );

      Comment

      • NewYorker
        New Member
        • Sep 2006
        • 13

        #4
        Our analysis of your code: COMPILER ERRORS

        Some suggestions:
        Unexpected identifiers: A, R, Suppose
        Just write an expression -- not a statement!
        There is no need for an assignment operator here.



        Originally posted by D_C
        Suppose numberOfPrizes = A*numberOfParti cipants+R.

        R = (numberOfPrizes % numberOfPartici pants);
        % is the modulo operation. Similarly for WidthOfWhatever .

        Use the modulo operation and test if it is 0.

        If J divides K, then ((J%K)==0).

        Comment

        • NewYorker
          New Member
          • Sep 2006
          • 13

          #5
          THANKS A MILLION ... I APPRECIATE YOUR HELP

          Originally posted by m013690
          Q1: ( numberOfPrizes % numberOfPartici pants == 0 );

          Q2: ( widthOfBox % widthOfBook != 0 );

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Originally posted by NewYorker
            Our analysis of your code: COMPILER ERRORS

            Some suggestions:
            Unexpected identifiers: A, R, Suppose
            Just write an expression -- not a statement!
            There is no need for an assignment operator here.
            That is because D_C did not supply code, they supplied the solution giving you the explaination in English of the operations required and made the reasonable assumption that you would be able to then understand how to solve your problem and write the solution for yourself.

            It appears you need to learn to recognise the difference between C and English

            Comment

            Working...