Due Wednesday, 1999/09/01
Note: Some of the following will be completed in Lab on Monday, 8/30.
/*
This program displays a conversion table
from dollars to pounds. It prompts the
user for the initial and final value in
dollars, the amount to increment by, and
the exchange rate.
*/
#include <stdio.h>
main()
{
float initial_dollars , increment_dollars, final_dollars , exchange_rate ;
float dollars , pounds ;
printf( "pounds -- prints a conversion table from dollars to pounds\n\n" ) ;
printf( "Enter the initial dollar amount\n" ) ;
scanf( "%f" , &initial_dollars ) ;
printf( "Enter the number of dollars by which to increment\n" ) ;
scanf( "%f" , &increment_dollars ) ;
printf( "Enter the final dollar amount\n" ) ;
scanf( "%f" , &final_dollars ) ;
printf( "Enter the exchange rate\n" ) ;
scanf( "%f" , &exchange_rate ) ;
printf( "\n" ) ;
printf( " Dollars Pounds\n" ) ;
dollars = initial_dollars ;
while( dollars <= final_dollars )
{
pounds = dollars * exchange_rate ;
printf( "%10.2f %10.2f\n" , dollars , pounds ) ;
dollars += increment_dollars ;
}
}
$ cc -o pounds pounds.c
This command instructs the C compiler ("cc") to create an output file ("-o") named "pounds" by reading the program file "pounds.c".
If all goes well, you should simply get another "$" command prompt. If something isn't exactly right with the program, you may get a number of error messages. If you get error messages, read them carefully, and use "pico pounds.c" to go back and see if you can change your program to correct them.
The program will prompt you for a series of values. If you enter 1, 1, 10, and 0.6543, you should see a screen that looks like this:$ ./pounds
pounds -- prints a conversion table from dollars to pounds
Enter the initial dollar amount
1
Enter the number of dollars by which to increment
1
Enter the final dollar amount
10
Enter the exchange rate
0.6543
Dollars Pounds
1.00 0.65
2.00 1.31
3.00 1.96
4.00 2.62
5.00 3.27
6.00 3.93
7.00 4.58
8.00 5.23
9.00 5.89
10.00 6.54
| Command | Description |
|---|---|
| ls | List the files in my directory. |
| ls -l | List the files in my directory in "long" format, showing file protections, ownerships, sizes, and dates. |
| mv file1 file2 | Rename (move) a file from the name file1 to the new name file2. |
| rm file | Delete (remove) a file. |
| pico file | Use the pico editor to create or modify a file. |
| cc -o executable-file source-file.c | Use the C compiler to read a C source-file.c and produce an executable-file. |
| ./executable-file | Invoke an executable-file produced by a compiler. |
As an exercise, try renaming your "pounds" executable file to "sterling", and then execute "sterling". Also, try deleting your "hello" executable file.
Copyright © 1999, Ray Ontko (rayo@ontko.com).