• Skip to main content
  • Skip to footer

CS50's Introduction to Computer Science on Edx: Supplementary resource

CS50 threads to aide as a supplementary resource

Argument type of a user defined function: Help correct syntax

CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1 › Argument type of a user defined function: Help correct syntax

  • This topic is empty.
Log In Register Lost Password
Viewing 1 post (of 1 total)
  • Author
    Posts
  • August 28, 2022 at 5:53 am #505
    admin
    Keymaster

      Facing hurdle in understanding the correct code for line 12:

      long amex = checkifamex(long y);

      I guess instead of long y as argument, there might be reference to function enterccno. Help regarding the correct syntax appreciated.


      Copy Code
      Copied
      Use a different Browser

      
      
      #include <stdio.h>
      #include <cs50.h>
      
      long enterccno (void);//long type as 14-digit credit card will not fit into the memory as int type
      long checkifamex (long enterccno);
      
      int main(void)
      {
          long y = enterccno();
          printf("credit card no. entered is %ld",y);
      
          long amex = checkifamex(long y);
          printf("entered amex is %ld",amex);
      }
      
      long enterccno (void) //It will take void as argument as the function will not initially take any particular long value as input to begin with.
      {
          long x = get_long("enter creditcardno");//get_long function by cs50.h leveraged to accept input of creditcard no. from user.
          return x;//stored x value or entered creditcardno transferred inside the main function when entercccno function called.
      }
      
      long checkifamex (long y)
      {
          long x = y;
          return x;
      }


      Reply


      The correct syntax on line 12 should be:

      long amex = checkifamex(y);

      [learn_press_profile]

    • Author
      Posts
    Log In Register Lost Password
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Log in / Register

    Initiative by Digital Splendid OPC Pvt. Ltd.