Learn How to Program in C

by
Dr. Kristin Switala

Introduction

Directives

Variables

Conditionals

Loops

Arrays

Pointers

Strings

Functions

Structures


Site Map

Review: Conditionals (c)

Instructions: Think about each question and write the answer in your notebook.


White Box Testing

1. Fix the errors in this C source code. There are 2 errors.

#include <stdio.h>
void main( )
{
char jazz;
printf("\nWhich of these instruments do you like best?");
printf("\nSaxophone (type s) \t Trumpet (type t)");
printf("\nGuitar (type g) \t Piano (type p)");
scanf("%c", &jazz);
switch( )
{

case 's':
printf("\nYou would like Charlie Parker and John Coltrane.");
break;
case 't':
printf("\nYou would like Miles Davis and Wynton Marsalis.");
break;
case 'g':
printf("\nYou would like Django Reinhardt and Pat Metheny.");
break;
case 'p':
printf("\nYou would like Bill Evans and Dave Brubeck.");
break;
default:
printf("\nError! You didn't select one of the choices.");
break;
}
}

Copyright
© 2001
Kristin Switala
Hosted by www.Geocities.ws

1