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

      Working on Week 2, Scrabble Lab 2.

      
      
      int compute_score(string word)
      {
          int n = strlen(word);
          char temp_upper;
          int score = 0;
          for(int i = 0; i< n; i++)
          {
              temp_upper = toupper(word);
              int point_index = temp_upper - 65;
              score = score + POINTS[point_index];
          }
          return score;
      }

       

      Source: https://github.com/volkansahn/CS50-Fall2020/blob/master/Week2/Lab2/scrabble.c

      I know referring blindly to answer might not be acceptable but doing so for the sake of understanding.

      Here are few of the things that I need to make clear:

      1. Is strlen an inbuilt function with used libraries (string.h/ctype.h) that computes length of a string?

      2. temp_upper = toupper(word); Does this command converts all entered letters to uppercase letters?

      3. int point_index = temp_upper – 65; All letters are converted to smallcase letters so that POINTS array can be applied?


      Reply


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

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