Homework 13: Flash Cards

Due: Tuesday 5/8 by 11:59pm

Objectives

Practice working with string functions from string library.

The Assignment


Write a program that helps a middle school student memorize the capitals of the fifty states in the United States. Your program should randomly select 1 of the 50 states and ask the user to type in the name of the capital. Your program should continue to quiz the user until the user types in 'quit'.

A sample run of your program might look like:

PT[131]% ./a.out
What is the capital of New Hampshire?
Nashua
Wrong! The capital of New Hampshire is Concord.

What is the capital of Rhode Island?
Providence
Right!

What is the capital of Minnesota?
Saint Paul
Right!

What is the capital of Oklahoma?
quit
Good-bye!
PT[132]% 

Use flash.c as the starting point of the program. The main program already has two arrays of strings defined for you: states and capitals. The first one has the names of all 50 states. The second one has the names of the 50 capitals. The two arrays are coordinated, so states[i] is the name of the i-th state and capitals[i] has the name of its capital city. For example, states[3] is "Arkansas" and capitals[3] is "Little Rock".

The main program in flash.c also seeds the random number generator for you.

Notes


Optional Embellishment

Add this feature to your program: when the user types in a wrong answer, check if the city is the capital of a different state. Then remind the user of this fact. For example:


PT[133]% ./a.out
What is the capital of New Hampshire?
Providence
Wrong! The capital of New Hampshire is Concord.
Providence is the capital of Rhode Island.

Submit

Use the script command to record several sample runs of your program. Then, submit your program and sample run as usual:


submit cs104_chang hw13 flash.c typescript