I had to define a simple macro for class in the professor's code
Heres the code -
Code:
#include <stdio.h> //this is to call printf() function to put output
#include <time.h> //this is to call clock() function that get the time
//define a MACRO COMPUTE_AVERAGE here
#define COMPUTE_AVERAGE(x, y) (((x)+(y))/2));
//define a function compute_average here
int computer_average(int num1,int num2);
int computer_average(num1, num2)
{
int avg = 0;
avg = ((num1 + num2)/2);
return (avg);
}
void main()
{
int i=1;
int j=5;
double ave=0.0;
int num1, num2;
int start_time, end_time;
int time_task1, time_task2;
//reading in two integers
printf("Enter an integer:\n");
scanf("%d", &num1);
printf("Enter another integer:\n");
scanf("%d", &num2);
//print the results computed by MACRO and function
printf("The average computed by your MACRO is: %10.2f\n", COMPUTE_AVERAGE(num1, num2) );
printf("The average computed by your function is: %10.2f\n", compute_average(num1, num2));
//get the starting time for the MACRO
start_time = clock();
printf("\nstart time1 %d\n", start_time);
while (i < 10000000)
ave = COMPUTE_AVERAGE(i++, j++); // macro call
//get the ending time for the MACRO
end_time = clock();
printf("end time1 %d\n", end_time);
time_task1 = end_time - start_time;
printf("The time elapsed for the Macro is: %d\n\n", time_task1);
i = 1;
j = 5;
//get the starting time for the function
start_time = clock();
printf("start time %d\n", start_time);
while (i < 10000000)
ave = compute_average(i++, j++); // regular function call
//get the ending time for the function
end_time = clock();
printf("end time %d\n", end_time);
time_task2 = end_time - start_time;
printf("The time elapsed for the regular function is: %d\n\n", time_task2);
return;
}
I get a compile time error on line 47 and 55 that reads " Syntax error before ')' token" I've tried multiple things to fix this but I have had no luck, any help would be appreciated.
Line 47 is
Code:
printf("The average computed by your MACRO is: %10.2f\n", COMPUTE_AVERAGE(num1, num2) );
and line 55 is
Code:
ave = COMPUTE_AVERAGE(i++, j++); // macro call