• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #44
    admin
    Keymaster

      Which part of the problem are you working on?

      Summing the digits

      What problem are you having?

      #include <stdio.h> 
      #include <cs50.h> 
      int main(void) 
      { 
          long creditcardno; 
          do 
          { 
              creditcardno = get_long("enter");
          } 
          while (creditcardno < 1000000000000 || creditcardno > 9999999999999999);
          int i = 0; 
          long cc = creditcardno; 
          while (cc > 0) 
          { 
              cc = cc / 10; 
              i++; 
          } 
          printf("%d", i);
      
         if (i == 14) 
         printf ("invalid"); 
         return 0; 
         int sum1 = 0; 
         int mod1 = 0; 
         int mm = creditcardno; 
         do 
             {mod1 = mm%10; 
             mm = mm/10; 
             sum1 = sum1 + mod1; 
             } 
          while (mm > 0); 
          printf ("number%d", sum1); 
      }
      
      

      While the program seems to be working for accepting input for credit card no. if only the digits are between 12 to 15 digits, and giving output of invalid if 14 digits entered, I am unable to get the sum of all the digits as part of solving the next leg of the problem.


      Reply


      https://edstem.org/us/courses/176/discussion/667982?answer=1606799[learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top