Computer Science 1511
Computer Science I

Laboratory Assignment 1
Introduction to C at UMD (5 points)
Due at the end of Lab


This lab will familiarize you with the use of Borland C for Windows on the UMD PC network. In this lab you will create a project, create files, compile, debug and run a program.

Using the Lab

If you are not in the lab for your scheduled lab time you will need to give your ID to a lab consultant to obtain a machine. Please check to see if someone is using the machine you were given. If so, look for a different machine. If the lab is full during your scheduled lab time, please ask your TA or the consultant to announce that it is a scheduled lab time for your class only.

Finding and Starting Turbo C

From the toolbar at the bottom of the Windows 95 desktop select the Start button. This will pop up a menu. Now from the menu select Programs - Borland C++Builder 3 - C++Builder 3 which brings up the C software. Your TA will help you with this during your first lab section.

Writing/Compiling Your Program

Once you have started up C++ Builder you will want to write your first program. Follow this link to a tutorial on how to do this.

Changing the Program

Once the program is working try to figure out how many guesses it will take the computer to find the number you are thinking of. Change the line of the program

  highest = 50;
  highest = 200;
See how many guesses it takes the program to find your number in that case.

Printing Your Program and Output

The tutorial has information on how to print your program and program output.

What To Hand In

Hand in the following items:

The Program

 * Your Name
 * CS 1511 Section ?
 * Today's date
 * Lab #1

#include <stdio.h>
int main() {
  int lowest;
  int highest;
  int found;
  int guess;
  int guesscount;
  char answer;

  lowest = 1;
  highest = 50;

  printf("Think of a number between %d and %d and I will try to guess it.\n",lowest,highest);

  printf("Type return when you are ready.\n");

  found = 0;
  guesscount = 0;
  while (!found) {
    guess = (lowest + highest) / 2;
    printf("Is the number %d (y/n)? ", guess);
    if ((answer == 'Y') || (answer == 'y')) {
      found = 1;
      printf("\nHooray!  Got it in %d guesses!\n",guesscount);
    else {
      printf("Is the number you are thinking of higher (h) or lower (l)? ");
      if ((answer == 'H') || (answer == 'h'))
        lowest = guess + 1;
        highest = guess - 1;
  printf("Press return to finish.");
  return 0;