CS156: Intro to C, Part I

Spring 2018

HW 3

CS156 HW3: Conversion                

Description                

For this assignment, you will write a program called rt.c that does two wildly unconnected things: show the most popular religions and convert temperatures from Fahrenheit to Celsius. (Some religions have hot & cold places—perhaps that connects the two.)                 

Fahrenheit to Celsius                

Religions by popularity                

Here are the ten most popular religions in the world, according to Wikipedia:                 

indexReligionPopularity
1Christianity31.2%
2Islam24.1%
3Secular/Nonreligious/Agnostic/Atheist16%
4Hinduism15.1%
5Buddhism 6.9%
6Chinese traditional religion 5.50%
7Ethnic religions 4.19%
8African traditional religions 1.40%
9Sikhism 0.32%
10Spiritism 0.21%

Sample Run                

“%” is the prompt and not a part of your program. Your input looks like this. Your output should match exactly.                 

    % c11 -Wall rt.c
    % ./a.out
    q: quit
    h: help
    r: info about a religion
    t: temperature conversion
    Command: t
    Fahrenheit: 212
    212.000000 Fahrenheit is 100.000000 Celsius
    Command: t
    Fahrenheit: 68.5
    68.500000 Fahrenheit is 20.277778 Celsius
    Command: z
    Invalid command
    Command: h
    q: quit
    h: help
    r: info about a religion
    t: temperature conversion
    Command: r
    Which religion? 5
    Buddhism: 6.9%
    Command: r
    Which religion? 3
    Secular/Nonreligious/Agnostic/Atheist: 16%
    Command: r
    Which religion? 100
    Don't know anything about religion #100.
    Command: r
    Which religion? 6
    Chinese traditional religion: 5.50%
    Command: t
    Fahrenheit: 65.5
    65.500000 Fahrenheit is 18.611111 Celsius
    Command: q

Required Functions                

You must define and use the following functions:                 

void print_menu();
Display the help menu, as shown above.
void religion(int);
Display the information about that particular religion. For example, religion(5) would display information about Buddhism. If the number is out of range, display as shown in the sample run.
double celsius(double);
Return the Celsius equivalent of a Fahrenheit temperature.

Note the difference between displaying something and returning something. celsius must not call printf. None of the required functions should call scanf.                 

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

How to submit your homework:                

Use web checkin, or:                 

    ~cs156/bin/checkin HW3 rt.c

Follow the directions on the homework page.                 

How to receive negative points:                

Turn in someone else’s work.                 

User: Guest                 

Check: HTML CSS
Edit History Source

Modified: 2018-03-12T11:15                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building