//========================================================================= #define PROGRAMMER "BAHN, William" #define PROG_CODE "bahw" #define COURSE "ECE-1021" #define YEAR (2003) #define TERM "Fall" #define SECTION (0) #define ASSIGNMENT "RWA 2.2" #define REVISION (0) #define TITLE "Real World Application from Section 2.2" #define SUBTITLE "Computing Distances" #define EMAIL "wbahn@eas.uccs.edu" #define FILENAME "rwa0202.c" //========================================================================= // PROBLEM: // // Assuming a constant rate of speed, compute the total distance traveled // given the total time elapsed. Repeatedly ask the user for times until // the user enters a time that is zero or less. // The time is to be entered in integer hours. // PSEUDOCODE // 1) GET: The first elapsed time from the user. // 2) LOOP: While the time is greater than zero. // 2.1) SET: distance = rate * time (rate = 14 km/hr) // 2.2) PUT: The distance to the screen // 2.3) GET: The total elapsed time from the user. // 3) PUT: Program Termination Message to screen. //== INCLUDE FILES ======================================================== #include // printf() //== FUNCTION PROTOTYPES ================================================== void PrintHeader(void); //== MAIN FUNCTION ======================================================== int main(void) { int distance, rate, time; PrintHeader(); printf("\n"); // Print a blank line rate = 14; // Rate in km/hr printf("Enter a time of zero or less to quit.\n"); printf("Enter the first time (in whole hours): "); scanf("%i", &time); while(0 < time) { distance = rate * time; // distance in km printf("In %i hrs at %i km/hr the distance traveled is %i km.\n", time, rate, distance); printf("\n"); // Print a blank line printf("Enter the next time (in whole hours): "); scanf("%i", &time); } printf("PROGRAM TERMINATED BY USER\n"); return(0); } //== SUPPORT FUNCTIONS ==================================================== void PrintHeader(void) { printf("========================================" "=======================================\n"); printf("Course....... %s-%i (%s %i)\n", COURSE, SECTION, TERM, YEAR); printf("Programmer... %s (%s)\n", PROGRAMMER, PROG_CODE); printf("Assignment... %s (Rev %i) (Source Code in %s)\n", ASSIGNMENT, REVISION, FILENAME); printf("Description.. %s\n", TITLE); printf(" %s\n", SUBTITLE); printf("========================================" "=======================================\n"); return; }