Exercise 2: Branching out! (40%)




Document: Software Engineering 1: Lab Exercises

next Conclusion
up Session 3: Week 6/7: Introducing C
gif Exercise 1: Hello World! (60%)

Exercise 2: Branching out! (40%)

Here is the program insult.c introduced in the lectures:

    #include <safe-c.h>

    void main(void)
    {
      string_type s;

      put_string("Welcome to INSULT!\n");
      put_string("What is your name?\n");
      get_string(s);

      if (string_equal(s, "Barry\n"))
        put_string("Hi, smarty pants!\n");
      else
        put_string("oooh - I don't like *you*!!!\n");

      put_string("Bye bye from INSULT...\n");
    }

Using this as a basis, or template, develop (plan, code, test, correct) a program called sport.c which will behave as follows:

  1. Display a suitable welcome/identification message.
  2. Ask the user to type in his or her favourite sport.
  3. If the topic is "Tennis", display the message "Tennis? I used to play Cricket!".
  4. If the topic is anything else, display the message "What a silly game!" instead.
  5. Finally display some suitable closing message.



McMullin@eeng.dcu.ie
Tue Apr 30 14:15:37 GMT 1996