Skip to content

This C program compares two words entered via command-line arguments and calculates a score for each word. The program determines the winner based on the higher score or declares "Play again!" for a tie.

Notifications You must be signed in to change notification settings

C-Coding-Assignments/Word-Score-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Word Score Game 🏆

This C program compares two words entered via command-line arguments and calculates a score for each word. The program determines the winner based on the higher score or declares "Play again!" for a tie.


Table of Contents 📖

Task 🛠️

Modify your program from project 2, task #2, to accept command-line arguments with single words instead of a sequence of words. The program should calculate the score for each word and compare them to determine the winner or prompt the user to "Play again!" in case of a tie.


Input and Output 🖥️

Input

  • The program should accept exactly two words as command-line arguments, excluding the program name.
  • If the number of arguments is not 3 (including the program name), print "invalid number of arguments".

Output

  • If the number of arguments is correct, the program will print either "John wins!" or "Play again!" depending on the score comparison of the two words.
  • If the number of arguments is incorrect, the program will print "invalid number of arguments".

Examples 📋

Example #1

Input:
./a.out

Output:
invalid number of arguments

Example #2

Input:
./a.out be bee

Output:
John wins!

Example #3

Input:
./a.out peach cheap

Output:
Play again!

Example #4

Input:
./a.out no hi

Output:
Play again!

Explanation:

  • In Example #1, the program was called without arguments, so it prints "invalid number of arguments".
  • In Example #2, the words "be" and "bee" result in "John wins!" based on their calculated scores.
  • In Example #3, the words "peach" and "cheap" have the same score, so the program outputs "Play again!".
  • In Example #4, the words "no" and "hi" have the same score, resulting in "Play again!".

Requirements ✔️

  1. The program must include the function:
    • int calculate_score(char *word);
    • This function calculates the score of a word, which could be based on letter positions, ASCII values, or any other scoring logic.
    • The function must use pointer arithmetic (not array subscripting) to visit array elements.
    • The program must check if the number of arguments is 3 (including the program name). If not, it should print "invalid number of arguments".

Usage 🚀

1. Compile the Program:

gcc -o word_score_game word_score_game.c

2. Run the Program:

./word_score_game word1 word2

3. Input Required:

  • Two words entered as command-line arguments.

About

This C program compares two words entered via command-line arguments and calculates a score for each word. The program determines the winner based on the higher score or declares "Play again!" for a tie.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages