-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6117 from SrVariable/main
Reto #47 - C
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
Retos/Reto #47 - LA PALABRA DE 100 PUNTOS [Fácil]/c/SrVariable.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |