Learn How to Program in C

by
Dr. Kristin Switala

Introduction

Directives

Variables

Conditionals

Loops

Arrays

Pointers

Strings

Functions

Structures


Site Map

Answers to Review: Variables (b)


General Questions

1. %f

2. %.2f

3. #define

4. a variable that remains the same at all times


Floating Point Variables

1. two errors:

  • in line 4, the variable should be float, not int
  • line 4 should end with a semicolon ;

2. one error:

  • the format specifier in line 5 should be %f, not %d

Working with Money

1. two errors:

  • line 5 should end with a semicolon ;
  • line 9 should use %.2f to limit the answer to 2 decimal places

2. five errors:

  • after the first line, add void main( )
  • the last printf statement has four errors; it should be:
    printf("\nHardback: $%.2f. With tax: $%.2f.", price, total);

Constants

1. four errors:

  • line 2 has two errors; it should be: #define HURLEY 1919 (no = sign)
  • line 9 should have the constant in capital letters: HURLEY
  • line 10 should use the %d format specifier, not %f
Copyright
© 2001
Kristin Switala
Hosted by www.Geocities.ws

1