Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Undefined references?

Tags:

c++

dev-c++

So this is a segment of my program, i am having trouble calling the the functions and I really need some help. It's basically to choose either function and enter data and later print that data. What am doing wrong ?please help, I keep getting

"[Linker] reference to Customer_Record()'" , [Linker error] undefined reference to Car_Record()' and "ld returned 1 exit status"

 #include <stdio.h>
 #include <string.h>  
 #include <stdlib.h>
 #include <windows.h>  
 #include <conio.h>

void Customer_Record(), Car_Record();
int num;

struct Customer {
    char customer_ID[20];
    int license;
    char address[20];
    int phone;
    char email[20];
} cust;

struct car {

    int regno[20];
    char model[20];
    char colour[10];
} car;


main() {
    printf("               Enter 1 to go to Customer Record \n\n");
    printf("               Enter 2 to go to Car Record \n\n");
    scanf("%d", &num);
    if (num = 1) {
        Customer_Record();
    } else if (num = 2) {
        Car_Record();
    } else {
        printf("Invalid Number");
    }

    system("cls");

    void Customer_Record(); {
        printf("********CUSTOMER RECORD********"); /* accepts into*/
        printf("\nEnter the name of the customer ");
        scanf("%s", &cust.customer_ID);
        printf("Enter the license number of the customer ");
        scanf("%d", &cust.license);
        printf("Enter the address of the customer ");
        scanf("%s", &cust.address);
        printf("Enter the cell phone number of the customer ");
        scanf("%d", &cust.phone);
        printf("Enter the email address of the customer ");
        scanf("%s", &cust.email);
    }

    void Car_Record(); {
        printf("********CAR RECORD********");
        printf("\nEnter the car's registration number ");
        scanf("%d", &car.regno);
        printf("Enter the car's model ");
        scanf("%s", &car.model);
        printf("Enter the colour of the car ");
        scanf("%s", &car.colour);
    }
    getchar();
    getchar();
}
like image 988
Terron Julien Avatar asked Apr 06 '26 18:04

Terron Julien


1 Answers

Don't nest your functions like that. The definitions of Customer_Record() and Car_Record() should be outside of main(). You need to take the ; off of the definitions of those functions, too.

Try formatting your code better - that will help a lot in the long run.

like image 119
Carl Norum Avatar answered Apr 09 '26 09:04

Carl Norum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!