Exercise 2: Branching out! (40%)
Document: Software Engineering 1: Lab Exercises
Conclusion
Session 3: Week 6/7: Introducing C
Exercise 1: Hello World! (60%)
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:
- Display a suitable welcome/identification message.
- Ask the user to type in his or her favourite sport.
- If the topic is "Tennis", display the message "Tennis?
I used to play Cricket!".
- If the topic is anything else, display the message
"What a silly game!" instead.
- Finally display some suitable closing message.
McMullin@eeng.dcu.ie
Tue Apr 30 14:15:37 GMT 1996