Question: Write a c program that gives you practice at using pointer variables to modify parameters as follows: 1.Create a function that corresponds with the following
Write a c program that gives you practice at using pointer variables to modify parameters as follows: 1.Create a function that corresponds with the following function comment:/*Function: getDouble()Parameter: double *pNumber: pointer to a variable that is filled in by the user input, if validReturn Value: bool: true if the user entered a valid floating-point number, false otherwise Description: This function gets a floating-point number from the user. If the user enters a valid floating-point number, the value is put into the variable pointed to by the parameter and true is returned. If the user-entered value is not valid, false is returned.*/a.It would likely be easiest if youchange the getNum() function to create this function.b.Use stdbool.h for the definitions of bool, true, and false as described in lecture.c.If you use sscanf(), you should be awarethat the appropriate format string for getting a double from the user is "%lf" (that's a lowercase L) and not "%f" (unlike printf).
2.Create a function that corresponds with the following function comment:/*Function: generateStats()Parameters: double d1, d2, d3: three floating-point numbersdouble *pAverage: pointer to a variable that is filled in by this function with the average of d1, d2, and d3 double *pSum: pointer to a variable that is filled in by this function with the sum of d1, d2, and d3Return Value: noneDescription: This function takes three floating-point numbers passed as doubles and calculates the average and sum of the numbers. Once calculated, the average gets put into the variable pointed to by the pAverage parameter and the sum gets put into the variable pointed to by the pSum parameter.*/a.This function should only have two lines in the body. pSum should be used in both lines(i.e. don't add the three numbers together twice). 3.In main:a.Declare three double variables.b.Prompt the user and get those three floating-point numbers using the getDouble() function. If any of the floating-point numbers are invalid, quit the program (do not use exit()).c.Declare a double variable for the average and another double variable for the sum.d.Call generateStats() passing the five variables as appropriate.e.Display the average and the sum.f.End with return 0.Make sure to prototype generateStatsand getDouble.Make sure that you use a header comment as described in the SET Submission Standards.Also, copy and paste the above function comments before the respective functions. No other comments are necessary #pragma warning(disable: 4996) int getNum(void) { /* the array is 121 bytes in size; we'll see in a later lecture how we can improve this code */ char record[121] = { 0 }; /* record stores the string */ int number = 0; /* NOTE to student: indent and brace this function consistent with your others */ /* use fgets() to get a string from the keyboard */ fgets(record, 121, stdin); /* extract the number from the string; sscanf() returns a number * corresponding with the number of items it found in the string */ if (sscanf(record, "%d", &number) != 1) { /* if the user did not enter a number recognizable by * the system, set number to -1 */ number = -1; } return number; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
