CSci 1001 Problem set 3. Due Wednesday, Nov 6 by 11:59pm.

Problem 1 (8 points): Elections result

Write a program that reads the names of two candidates, then asks you to enter the number of votes for each person, and then prints the the name of the winner. If it's a tie, it has to say so.

For instance, the dialog with the program may go like this (using prompts to read the data):

If it's a tie, print something like "Bart Simpson and Lisa Simpson got equal number of votes".

Problem 2 (10 points): fix a mistake in the program

The following program converts percent values into letter grades (with the 10% scale, i.e. 90-100 is A, 80-89 is B, etc.). It works, but has mistakes in its logic so it gives wrong results for some inputs.
You may assume that the number entered is always between 0 and 100. There are no "plus" or "minus" grades, such as B-.

Your task is as follows:
  1. Give at least two examples of data for which it gives incorrect results, clearly explain why (list the specific comparisons that the data goes through in each example)
  2. Fix the mistakes. You might want to change the comparison part quite a bit. Make your correct program very clear.
  3. Test your program to make sure that it works correctly (try the inputs that were working in the wrong version to make sure that they still work). Write down what data you tested it with
  4. What would be your advice on how to avoid similar mistakes in conditionals in the future?

<!DOCTYPE html>
an INCORRECT program for converting from numeric 
to letter grades for CSci 1001 problem set
Author: Elena Machkasova
Last modified: 10/16/2008

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
Fix this program!
<h1>Converting to letter grades</h1>

<script type="text/javascript" language="javascript">
var numeric = window.prompt("Please enter your numeric grade: ", "");
numeric = parseFloat(numeric);

if (numeric > 90) {
	document.write("Your letter grade is A");
} else if (numeric < 80)  {
	document.write("Your letter grade is C");
} else if (numeric < 70)  {
	document.write("Your letter grade is D");
} else if (numeric < 60)  {
	document.write("Your letter grade is F");
} else {
	document.write("Your letter grade is B");



Problem 3 (10 points)

Exercises 12, 14, 15, 19, 21 p. 117.

How to submit

Send all of your program files to me by e-mail. You may submit the written part (if any) in class or send it together with your problem set. Please send only ONE e-mail with your entire submission, make sure you include everything. Multiple e-mails with your homework may result in a lower grade.

CSci 1001 course web site.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.