Description
Objectives
1. To give students practice at typing in, compiling and running simple programs.
2. To learn how to read in input from the user.
3. To learn how to use assignment statements and arithmetic expressions to make calculations
Introduction: Programmers for a Better Tomorrow
Programmers for a Better Tomorrow is an organization dedicated to helping charities, medical
societies, and scholarship organizations manage various tasks so that they can focus on making
the world a better place! They have asked you and your classmates to help them develop some
new programs to benefit their organizations.
Problem: Knitting for Fun and Non-Profit (knit.c)
One of the programs that Programmers for a Better Tomorrow supports knits hats, sweaters,
and blankets for people who may not have enough to keep them warm. These may be sent to
other places in the country or overseas.
In this program, you will ask the user how many balls of yarn they have on hand and how many
yards of yarn each ball contains. Then, based on the total number of yards the user has, your
program can determine how many hats OR sweaters can be made.
It takes 225 yards to make a hat and 450 yards to make a sweater. If the user has 500 total
yards, they would be able to make two hats or one sweater. Your program should print this
information for the user.
Input Specification
1. The number of balls of yarn the user has, n, where n is an integer greater than zero.
2. The number of yards in each ball, y, where y is an integer greater than zero.
Output Specification
Output the result using the format below:
You can make X hats or Y sweaters.
Output Sample
Below are some sample outputs of running the program. Note that these samples are NOT a
comprehensive test. You should test your program with different data than is shown here based
on the specifications given above.
In the sample run below, for clarity and ease of reading, the user input is given in italics while
the program output is in bold. (Note: When you actually run your program no bold or italics
should appear at all. These are simply used in this description for clarity’s sake.)
2
Sample Run #1
How many balls of yarn do you have?
6
How many yards are in each ball of yarn?
100
You can make 2 hats or 1 sweaters.
Sample Run #2
How many balls of yarn do you have?
5
How many yards are in each ball of yarn?
50
You can make 1 hats or 0 sweaters.
Sample Run #3
How many balls of yarn do you have?
3
How many yards are in each ball of yarn?
425
You can make 5 hats or 2 sweaters.
Deliverables
One source files – knit.c – is to be submitted over WebCourses.
Restrictions
Although you may use other compilers, your program must compile and run using Code::Blocks.
Your program should include a header comment with the following information: your name,
course number, section number, assignment title, and date. Also, make sure you include
comments throughout your code describing the major steps in solving the problem.
Grading Details
Your programs will be graded upon the following criteria:
1) Your correctness
2) Your programming style and use of white space. Even if you have a plan and your program
works perfectly, if your programming style is poor or your use of white space is poor, you could
get 10% or 15% deducted from your grade.
3) Compatibility – You must submit C source files that can be compiled and executed in a
standard C Development Environment. If your program does not compile, you will get a sizable
deduction from your grade.