define CRTSECURENOWARNINGS include include prog5functionsh i

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include \"prog5_functions.h\"

#include <math.h>

double low_point, high_point, result, hp, lp, result2, x, change_in_x, function_of_x_at_lp, function_of_x_at_hp;

int traps, number_of_traps;

char yayornay, junk;

int main()

{

while(1)

{

printf(\"Enter low point:\ \");

scanf(\"%lf\", &low_point);

printf(\"Enter high point:\ \");

scanf(\"%lf\", &high_point);

printf(\"Enter number of trapezoids:\ \");

scanf(\"%d\", &traps);

lp=low_point;

x=0;

number_of_traps=0;

while(number_of_traps!=traps)

{

hp=lp+((high_point - low_point)/traps);

  

change_in_x = (high_point - low_point) / traps;

function_of_x_at_lp = (sin(lp)+(lp*lp)/10);

function_of_x_at_hp = (sin(hp)+(hp*hp)/10);

  

if(function_of_x_at_lp<function_of_x_at_hp)

{result = (function_of_x_at_lp * change_in_x) + (((function_of_x_at_hp - function_of_x_at_lp) * change_in_x)/2);}

  

if(function_of_x_at_hp<function_of_x_at_lp)

{result=(function_of_x_at_hp * change_in_x) + (((function_of_x_at_lp - function_of_x_at_hp) * change_in_x)/2);}

  

lp = lp + change_in_x;

  

  

x=x+result;

number_of_traps = number_of_traps+1;

}

printf(\"%lf\ \", x);

do

{

scanf(\"%c\", &junk);

}

while (junk != \'\ \');

}}

The code runs perfectly, however it has to be written in a separate function folder in the following format:

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

#include <math.h>

#include \"prog5_functions.h\"

// Calculate integral of f(x) over interval min to max, using n trapezoids

double integrate(double min, double max, int n) {

/*************************************************

   COMPLETE THIS FUNCTION WITH APPROPRIATE CODE

   *************************************************/

printf(\"integrate() doesn\'t work!\ \");

return 0;

}

// f(x) as defined in the program specification

double f(double x) {

/*************************************************

   COMPLETE THIS FUNCTION WITH APPROPRIATE CODE

   *************************************************/

printf(\"f() doesn\'t work!\ \");

return 0;

}

// Used to clear line if input formatting error occurs

void badInput() {

/*************************************************

   COMPLETE THIS FUNCTION WITH APPROPRIATE CODE

   *************************************************/

}

So, how would I translate my code into a function, and then incorporate it? Thank you. I have trouble with functions at the moment.

Solution

void badInput() {

if(max-min<0)

{

fflush(stdout);

}

main()

{

{

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include \
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include \
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site