I created an article previously doing this program in C++, but now I am trying to convert it to C.
#include<stdio.h>
double hamCalc(double b, double p);
double cheeseCalc(double b, double p, double c);
double dcheeseCalc(double b, double p, double c);
int main()
{
double patty, bun, cheese;
printf("This is the C version.\n\n");
scanf("Enter the price for each patty: %d", &patty);
scanf("Enter the price for each bun: %d", &bun);
scanf("Enter the price for each cheese slice: %d", &cheese);
double val1 = hamCalc(bun, patty);
double val2 = cheeseCalc(bun, patty, cheese);
double val3 = dcheeseCalc(bun, patty, cheese);
printf("Hamburger price: %.2f", val1);
printf("Cheeseburger price: %.2f", val2);
printf("Double Cheeseburger Price: %.2f", val3);
}
double hamCalc(double b, double p)
{
double total = b + p;
double total2 = total / 2;
total = total + total2;
return total;
}
double cheeseCalc(double b, double p, double c)
{
double total = b + p + c;
double total2 = total / 2;
total = total + total2;
return total;
}
double dcheeseCalc(double b, double p, double c)
{
double total = b + p + p + c + c;
double total2 = total / 2;
total = total + total2;
return total;
}
I compile it by
gcc -c burger.c
Now, my first question is, do I try and run the 'burger.c' file or do i compile the created 'burger.o' file because when I try the .o file it says 'cannot execute binary file'.
However, when I run the 'burger.c' file, I get an error saying:
./burger.c: line 2: syntax error near unexpected token (' ./burger.c: line 2:
double hamCalc(double b, double p);'
Anyone know whats up? Thanks in advance. I plan on splitting these functions later on into separate files using a makefile but wanted to debug before everything is in separate places.