Skip to content

Commit

Permalink
Reto mouredev#47 - C
Browse files Browse the repository at this point in the history
  • Loading branch information
SrVariable committed Dec 18, 2023
1 parent ec7615f commit 2176465
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [Fácil]/c/SrVariable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#define WORD_LENGTH 1024
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int add_points(char *word)
{
int counter;

counter = 0;
for (int i = 0; word[i]; i++)
{
if (word[i] == ' ')
break ;
else if (isupper(word[i]))
counter += word[i] - 'A' + 1;
else if (islower(word[i]))
counter += word[i] - 'a' + 1;
}
return (counter);
}

int main(void)
{
int points;
char *word;

points = 0;
word = calloc(WORD_LENGTH, 1);
if (!word)
return (1);
while (points != 100)
{
printf("Introduce a word: ");
if (!fgets(word, WORD_LENGTH, stdin))
{
free(word);
return (2);
}
points = add_points(word);
printf("Word Score: %d\n", points);
if (points > 100)
printf("Too high!\n");
else if (points < 100)
printf("Too low!\n");
}
printf("You won!");
free(word);
return (0);
}

0 comments on commit 2176465

Please sign in to comment.