Learn How to Program in C

by
Dr. Kristin Switala

Introduction

Directives

Variables

Conditionals

Loops

Arrays

Pointers

Strings

Functions

Structures


Site Map

Review: Loops (a)

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( )
{
int answer;
while(answer !! 10) {

printf("\nHow many rings does the planet Uranus have? ");
scanf("%d", &answer);
}
printf("/nYes, Uranus has %d rings.", answer);
}

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

#include <stdio.h>
void main( )
{
char answer;
while(answer != 'j') {

printf("\nWhich planet is larger: Jupiter (type j) or Saturn (type s)? ");
scanf("%c", &answer);
}
printf("\nYes, Jupiter is the largest planet.");
}

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

#include <stdio.h>
void main( )
{
char planet;
while(planet != 'u') {

printf("\nWhich planet rotates up and down, instead of side to side?);
printf("\nJupiter (type j) \t Saturn (type s) \t Uranus (type u) ");
scanf(" %c", &planet);
}
printf("\nYes, Uranus was knocked on its side by some huge impact.);
}

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

#include <stdio.h>
void main( )
{
char winds;
while(winds != 'n')
{

printf("\nWhich planet has winds up to 2000 km/hr?");
printf("\nJupiter (type j) \t Saturn (type s)");
printf("\nUranus (type u) \t Neptune (type n) ");
scanf("%c", &wins);
}
printf("\nYes, Neptune has the fastest winds in the Solar System.");
}

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

1