- This topic has 0 replies, 1 voice, and was last updated 4 years ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
› Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2: [Arrays] – Functions, Variable and Scope, Debugging, Arrays, and Command Line Arguments › Understanding define function with Scrabble lab
Tagged: const, define function, scrabble lab problem
I fail to understand define command while taking a look at template code provided that does not have mention of define command. Since there is no TODO after #include, I guess define command is not needed or at least not mandatory.
A similar problem with input of months has define command:
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include <stdio.h>
#define MONTHS 12
int main(void)
{
int days[MONTHS] = {31,28,31,30,31,30,31,31,30,31,30,31};
int index;
for (index = 0; index < MONTHS; index++)
printf("Month %d has %2d days.\n", index +1,
days[index]);
return 0;
}
[/dm_code_snippet]
Is it desirable to mention define with POINTS? Or it is wrong for this problem:
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
#include <stdio.h>
#include <cs50.h>
#include <ctype.h>
#include <string.h>
#define POINTS 26
// Points assigned to each letter of the alphabet
int POINTS[] = {1, 3, 3, 2, 1, 4, 2, 4, 1, 8, 5, 1, 3, 1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10};
int compute_score(string word);
[/dm_code_snippet]
Reply
https://edstem.org/us/courses/176/discussion/842067?answer=1929475[learn_press_profile]
