Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What to Do Download the file get-numbers.c. Read the code, then build an executable and run it a few times to see if it

What to Do Download the file get-numbers.c. Read the code, then build an executable and run it a few times toThe get_input function should make calls to get_double_or_exit and get_int_or_exit-you can copy and paste the  
456789 18 19 20 21 22 23 24 25 26 10 11 // PROMISES: 12 // 13 // 14 // 15 // 16 17 27 28 29 30 31 32 33 34 35

What to Do Download the file get-numbers.c. Read the code, then build an executable and run it a few times to see if it behaves the way you expect. Then add a definition for get_double_or_exit, and add code to main that will allow you to test your definition. Note: A sequence of digits without a decimal point-such as 123-can be read into an int and also into a double. get_double_or_exit ahould accept that kind of input. Exercise B: Writing a complete program What to Do The program you will write here will be a simple utility for a long-distance runner. The input will be a distance and a time, and the output will be the average times taken per kilometre and per mile. Write a program that asks a user for a distance in kilometres, as a double, and a time interval, as an int and a double; a number of minutes, and a number of seconds. If the program succeeds in reading all three numbers, it should report the output specified above. Here is a sample of a successful dialogue with the program, with slanted typewriter font used to show what was typed by a user: Please enter a distance in km, using type double. 10.0 I read a double value of 10.000000. Please enter a number of minute, using type int. 39 I read an int value of 39. Please enter a number of seconds, using type double. 47.2 I read a double value of 47.200000. Distance run: 10.000000 km. Time of run: 39 minute(s), 47.200000 second(s). Average time for 1 km: 3 minute(s), 58.720000 seconds (s). Average time for 1 mile: 6 minute(s), 24.182600 seconds(s). And here is a sample of an unsuccessful dialogue: Please enter a distance in km, using type double. No! You can't make me! I could not read a double. I am quitting. For the most part, you may organize your program however you see fit, except for the following, which I insist on, so that you get practice with some of the key C features used in previous lab exercises: The three input numbers should be collected by a function with exactly this prototype: void get input (double .km in, int minutes in, double seconds_in); The get_input function should make calls to get_double_or_exit and get_int_or_exit-you can copy and paste the prototypes and definitions from Exercise A. Note: 1 mile is exactly 1609.344 metres. What to Include in your PDF Submission Include a complete listing of your program source code, and a listing of terminal input/output showing a few tests, including: 42.195 km in 179 minutes, 33.6 seconds; 1.609344 km in 3 minutes, 59.2 seconds; various kinds of inputs that the program can't read. 456789 18 19 20 21 22 23 24 25 26 10 11 // PROMISES: 12 // 13 // 14 // 15 // 16 17 27 28 29 30 31 32 33 34 35 36 37 38 #include #include 39 40 41 int get_int_or_exit(void); // REQUIRES: // User has been prompted to enter an int. Function tries to read an int using scanf and "%d" On success, that int is echoed to the user, and the int is the function return value. On failure, and error message is printed and exit is called with an argument of 1. double get_double_or_exit(void); // Like get_int_or_exit, but tries to read a double using "%lf". int main(void) { int i; printf("Testing get_int_or_exit. Please enter a line of text i = get_int_or_exit(); printf("get int_or_exit returned a value of %d. ", i); return 0; int get_int_or_exit (void) { int result; if (1 l = scanf("%d", &result)) { printf("I could not read an int. I am quitting. "); exit (1); } printf("I read an int value of %d. ", result); return result;

Step by Step Solution

3.54 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

include include void getdoubleorexitconst char prompt double value printfs prompt if scanflf value 1 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions