Issue
I am working on a homework assignment for my computer science class and, we are required to develop this simple program for our first use of C.
I was able to create the program through a straight gcc
compile, but while using gcc -lm -Wall -o
compile, my program crashes and returns
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What would cause my program to crash when entering it into the second compile?
My code
#include <stdio.h>
void main() {
float enrollment, fullsec, leftover, recieveA, recieveB, recieveC, recieveD;
printf("Program #1, masc0865, Tom Bachar");
printf("Enter enrollments on one line: ");
scanf("%f", &enrollment);
fullsec = enrollment/25;
leftover = enrollment%25;
printf("Enrollment = %f", enrollment);
printf("Amount of Full Sections = %f", fullsec);
printf("Students Left Over = %0.2f", leftover);
recieveA = enrollment*.30;
recieveB = enrollment*.25;
recieveC = enrollment*.15;
recieveD = enrollment*.30;
printf("Students expected to receive an A: %f", recieveA);
printf("Students expected to receive a B: %f", recieveB);
printf("Students expected to receive a C: %f", recieveC);
printf("Students expected to receive some other grade: %f", recieveD);
}
Solution
To compile your code with gcc, you also need to pass in the names of your source files. So if you had a source file named project1.c
, you could compile it by running:
gcc -lm -Wall -o a.out project1.c
Assuming your code successfully compiled (no errors), you could run it by then doing:
./a.out
That being said, your code won't compile. You can't use the modulus operator against a floating point number.
foo.c:9:25: error: invalid operands to binary expression ('float' and 'float')
leftover= enrollment%25;
~~~~~~~~~~^~~
Answered By - Bill Lynch Answer Checked By - Mary Flores (WPSolving Volunteer)