Learn How to Program in C

by
Dr. Kristin Switala

Introduction

Directives

Variables

Conditionals

Loops

Arrays

Pointers

Strings

Functions

Structures


Site Map

Review: Conditionals (a)

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


General Questions

1. What are the 3 parts of a conditional?

2. What is a nested conditional?


White Box Testing

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

#include <stdio.h>
void main( )
{
char answer;
printf("\nWhich volcano, in 1500 BC, had a massive eruption,");
printf("\nand led to the demise of Minoan civilization?");
printf("\nWas it Krakatoa (type k), Thera (type t), or Vesuvius (type v)? ");
scanf("%c", &answer);
if(answer = 't')

printf("\nYes, Thera erupted in 1500 BC.");
else
printf("\nNo, it was Thera that erupted.");
}

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

#include <stdio.h>
void main( )
{
int year;
printf("What year were you born? ");
scanf("%d", year);
if(year < 1991)
{

printf("\nYou must remember when Mt. Pinatubo erupted.");
if(year < 1980)
{
printf("\nYou must also remember Mt. St. Helens' eruption.");


}
else
printf("\nYou must remember when Soufriere Hills destroyed Montserrat.");
}

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

1