3
answers
0
watching
157
views

Hello. Im looking to have someone go over my C code and then send back to me without any errors you find. I realy need this code to give me the output its required too. Its a long code and could be chalenging. Thank you.                                                                                                                                                                                                                                                          #include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Define constants for car prices
#define KIA_PRICE 20000
#define TOYOTA_PRICE 25000
#define HONDA_PRICE 22000
#define MAZDA_PRICE 23000
#define NISSAN_PRICE 24000
#define FORD_PRICE 35000
#define GENESIS_PRICE 40000
#define VOLVO_PRICE 45000
#define ACURA_PRICE 30000
#define BMW_PRICE 50000
#define AUDI_PRICE 55000
#define BENTLEY_PRICE 80000
#define FERRARI_PRICE 100000
#define ASTON_MARTIN_PRICE 90000
#define BUGATTI_PRICE 150000

// Define global variables for car inventory
int kiaInventory = 5;
int toyotaInventory = 3;
int hondaInventory = 2;
int mazdaInventory = 4;
int nissanInventory = 6;
int fordInventory = 7;
int genesisInventory = 2;
int volvoInventory = 3;
int acuraInventory = 5;
int bmwInventory = 4;
int audiInventory = 2;
int bentleyInventory = 1;
int ferrariInventory = 1;
int astonMartinInventory = 0;
int bugattiInventory = 0;

// Define car struct
typedef struct {
    char model[50];
    char manufacturer[50];
    char color[20];
    int mileage;
    char transmission[20];
    char engine[50];
    char chassis[50];
    char exterior[50];
    char seatingTrim[50];
    char dimensions[50];
    int airbags;
    int fuelEconomy;
    int isHybrid;
    int isFullyElectrified;
    int hasAutoParkingAssistance;
    int hasNightVisionAssistance;
    int hasCruiseControl;
    int is2WD;
    int hasHillAssist;
    int hasTPMS;
    int hasVoiceCommand;
    int hasLaneChangeIndicator;
    int hasForwardCollisionWarningSensor;
    int hasBlindSpotWarningSensors;
    int seatHeater;
    int hasSteeringHeater;
} Car;

// Define branch struct
typedef struct {
    char address[100];
    char postalCode[10];
    char phoneNumber[15];
    char faxNumber[15];
    char customerServiceEmail[50];
    char generalManagerName[50];
    char generalManagerPhoneNumber[15];
    char generalManagerCellPhoneNumber[15];
    char generalManagerAddress[100];
    char generalManagerEmail[50];
    char generalManagerDateOfEmployment[20];
    int generalManagerYearsOfExperience;
    char financeManagerName[50];
    char financeManagerPhoneNumber[15];
    char financeManagerCellPhoneNumber[15];
    char financeManagerAddress[100];
    char financeManagerDateOfEmployment[20];
    int financeManagerYearsOfExperience;
    int numAvailableCars;
    Car availableCars[10];
} Branch;

// Define currency conversion rates
float usdToCad = 1.3;
float usdToMxn = 20.0;

// Function prototypes
void displayMenu();
void showCars(Branch branch);
void buyCar(Branch *branch);
void transferCar(Branch *sourceBranch, Branch *destinationBranch);
void supplyCars(Branch *branch);

int main() {
    Branch myBranch; // Replace with your branch name
    strcpy(myBranch.address, "1234 Main St");
    strcpy(myBranch.postalCode, "M5G
#define TOYOTA_CAMRY_PRICE 25000
#define HONDA_CIVIC_PRICE 22000
#define FORD_MUSTANG_PRICE 35000

// Define global variables for car inventory
int toyotaCamryInventory = 5;
int hondaCivicInventory = 3;
int fordMustangInventory = 2;

// Define struct for car information
struct Car {
char model[50];
char manufacturer[50];
char color[20];
int mileage;
int isBrandNew;
float price;
};

// Define struct for branch information
struct Branch {
char address[100];
char postalCode[10];
char phoneNumber[15];
char faxNumber[15];
char customerServiceEmail[50];
char generalManagerName[50];
char generalManagerPhoneNumber[15];
char generalManagerCellPhoneNumber[15];
char generalManagerAddress[100];
char generalManagerEmail[50];
char generalManagerDateOfEmployment[20];
int generalManagerYearsOfExperience;
char financeManagerFirstName[50];
char financeManagerLastName[50];
char financeManagerPhoneNumber[15];
char financeManagerCellPhoneNumber[15];
char financeManagerAddress[100];
char financeManagerDateOfEmployment[20];
int financeManagerYearsOfExperience;
int availableCars;
struct Car carInventory[10];
};

// Define function to display menu
void displayMenu() {
printf("Welcome to Michael Banvill's Car Dealership!\n");
printf("1. Show available cars\n");
printf("2. Buy a car\n");
printf("3. Exit\n");
}

// Define function to show available cars
void showCars(struct Branch *branch) {
printf("Available cars:\n");
for (int i = 0; i < branch->availableCars; i++) {
printf("%d. %s %s - Price: $%.2f, Inventory: %d\n", i + 1, branch->carInventory[i].manufacturer,
branch->carInventory[i].model, branch->carInventory[i].price, branch->carInventory[i].isBrandNew);
}
}

// Define function to buy a car
void buyCar(struct Branch *branch) {
int choice;
printf("Enter the number of the car you want to buy: ");
scanf("%d", &choice);

arduino
Copy code
if (choice < 1 || choice > branch->availableCars) {
    printf("Invalid choice. Please try again.\n");
    return;
}

struct Car *car = &branch->carInventory[choice - 1];

if (car->isBrandNew) {
    printf("You are buying a brand-new car.\n");
    printf("The price is $%.2f.\n", car->price);
} else {
    printf("You are buying a used car.\n");
    printf("The price is $%.2f.\n", car->price * 0.9);
}

printf("Confirm purchase? (1 for Yes, 0 for No): ");
int confirm;
scanf("%d", &confirm);

if (confirm == 1) {
    printf("Thank you for your purchase!\n");
    branch->availableCars--;
} else {
    printf("Purchase canceled.\n");
}
}

int main() {
struct Branch branch1 = {
.address = "1234 Elm Street",
.postalCode = "M1A 1A1",
.phoneNumber = "416-123-4567",
.faxNumber = "416-987-6547",
void transferCar() {
    int sourceBranch, destinationBranch, carChoice, quantity;
    float transferExpense, currencyRate;
    char currency[4];
    
    printf("Enter source branch: ");
    scanf("%d", &sourceBranch);
    printf("Enter destination branch: ");
    scanf("%d", &destinationBranch);
    
    // Get transfer expense and currency rate
    printf("Enter transfer expense: ");
    scanf("%f", &transferExpense);
    printf("Enter currency rate: ");
    scanf("%f", &currencyRate);
    printf("Enter currency (USD, CAD, MXN): ");
    scanf("%s", currency);
    
    printf("Select car to transfer:\n");
    printf("1. Toyota Camry\n");
    printf("2. Honda Civic\n");
    printf("3. Ford Mustang\n");
    scanf("%d", &carChoice);
    
    printf("Enter quantity to transfer: ");
    scanf("%d", &quantity);
    
    // Update inventory of source branch
    switch(carChoice) {
        case 1:
            if(quantity > toyotaCamryInventory) {
                printf("Error: Not enough inventory in source branch.\n");
                return;
            }
            toyotaCamryInventory -= quantity;
            break;
        case 2:
            if(quantity > hondaCivicInventory) {
                printf("Error: Not enough inventory in source branch.\n");
                return;
            }
            hondaCivicInventory -= quantity;
            break;
        case 3:
            if(quantity > fordMustangInventory) {
                printf("Error: Not enough inventory in source branch.\n");
                return;
            }
            fordMustangInventory -= quantity;
            break;
        default:
            printf("Error: Invalid choice.\n");
            return;
    }
    
    // Update inventory of destination branch
    switch(carChoice) {
        case 1:
            toyotaCamryInventory += quantity;
            break;
        case 2:
            hondaCivicInventory += quantity;
            break;
        case 3:
            fordMustangInventory += quantity;
            break;
    }
    
    // Update transfer expenses and currency rate
    switch(carChoice) {
        case 1:
            transferExpense *= currencyRate;
            break;
        case 2:
            transferExpense *= currencyRate;
            break;
        case 3:
            transferExpense *= currencyRate;
            break;
    }
    
    printf("%d car(s) of choice %d transferred from branch %d to branch %d.\n", quantity, carChoice, sourceBranch, destinationBranch);
    printf("Transfer expense: %.2f %s\n", transferExpense, currency);
}

void supplyCars() {
    int branchChoice;
    float rebatePercentage;
    
    printf("Enter branch to supply cars: ");
    scanf("%d", &branchChoice);
    
    printf("Enter rebate percentage: ");
    scanf("%f", &rebatePercentage);
    
    switch(branchChoice) {
        case 1:
            // Apply rebate for brand-new Honda in Canada
            if(rebatePercentage > 0 && rebatePercentage <= 100) {
                toyotaCamryInventory += 5;
                TOYOTA_CAMRY_PRICE *= (1 - rebatePercentage/100);
                printf("Supplying 5 brand-new Toyota Camry to branch %d with a rebate of %.2f%%\n", branchChoice, rebatePercentage);
            } else {
                printf("Error: Invalid rebate percentage.\n");
            }
            break;
        case 2:
            // Apply rebate for brand-new Volvo above $60,000 in Mexico
            if(rebatePercentage > 0 && rebatePercentage <= 100) {
                hondaCivic

Inventory += 3;
HONDA_CIVIC_PRICE *= (1 - rebatePercentage/100);
printf("Supplying 3 brand-new Honda Civic to branch %d with a rebate of %.2f%%\n", branchChoice, rebatePercentage);
} else {
printf("Error: Invalid rebate percentage.\n");
}
break;
case 3:
// Apply rebate for brand-new Ford above $50,000 in USA
if(rebatePercentage > 0 && rebatePercentage <= 100) {
fordMustangInventory += 2;
FORD_MUSTANG_PRICE *= (1 - rebatePercentage/100);
printf("Supplying 2 brand-new Ford Mustang to branch %d with a rebate of %.2f%%\n", branchChoice, rebatePercentage);
} else {
printf("Error: Invalid rebate percentage.\n");
}
break;
default:
printf("Error: Invalid branch choice.\n");
break;
}
}

void displayInventory() {
printf("Inventory at Branch 1 (Canada):\n");
printf("Toyota Camry: %d cars\n", toyotaCamryInventory);
printf("Inventory at Branch 2 (Mexico):\n");
printf("Honda Civic: %d cars\n", hondaCivicInventory);
printf("Inventory at Branch 3 (USA):\n");
printf("Ford Mustang: %d cars\n", fordMustangInventory);
}

int main() {
int choice;

arduino
Copy code
while(1) {
    printf("Car Dealership Inventory System\n");
    printf("1. Transfer car\n");
    printf("2. Supply cars\n");
    printf("3. Display inventory\n");
    printf("4. Exit\n");
    printf("Enter your choice: ");
    scanf("%d", &choice);
    
    switch(choice) {
        case 1:
            transferCar();
            break;
        case 2:
            supplyCars();
            break;
        case 3:
            displayInventory();
            break;
        case 4:
            printf("Exiting...\n");
            return 0;
        default:
            printf("Error: Invalid choice.\n");
            break;
    }
}
}

// Global variables for inventory and prices
int toyotaCamryInventory = 10;
float TOYOTA_CAMRY_PRICE = 25000.0;

int hondaCivicInventory = 8;
float HONDA_CIVIC_PRICE = 22000.0;

int fordMustangInventory = 6;
float FORD_MUSTANG_PRICE = 50000.0;

// Function to transfer cars between branches
void transferCar() {
    int branchFrom, branchTo, carChoice, quantity;
    
    printf("Transfer Car\n");
    printf("Enter branch to transfer from (1-3): ");
    scanf("%d", &branchFrom);
    printf("Enter branch to transfer to (1-3): ");
    scanf("%d", &branchTo);
    
    if(branchFrom < 1 || branchFrom > 3 || branchTo < 1 || branchTo > 3) {
        printf("Error: Invalid branch choice.\n");
        return;
    }
    
    printf("Car Choices:\n");
    printf("1. Toyota Camry\n");
    printf("2. Honda Civic\n");
    printf("3. Ford Mustang\n");
    printf("Enter car choice (1-3): ");
    scanf("%d", &carChoice);
    
    if(carChoice < 1 || carChoice > 3) {
        printf("Error: Invalid car choice.\n");
        return;
    }
    
    printf("Enter quantity to transfer: ");
    scanf("%d", &quantity);
    
    switch(carChoice) {
        case 1:
            if(branchFrom == 1) {
                if(quantity > toyotaCamryInventory) {
                    printf("Error: Insufficient inventory at branch %d.\n", branchFrom);
                } else {
                    toyotaCamryInventory -= quantity;
                    toyotaCamryInventory += quantity;
                    printf("Transferring %d Toyota Camry from branch %d to branch %d.\n", quantity, branchFrom, branchTo);
                }
            } else {
                printf("Error: Car not available at branch %d.\n", branchFrom);
            }
            break;
        case 2:
            if(branchFrom == 2) {
                if(quantity > hondaCivicInventory) {
                    printf("Error: Insufficient inventory at branch %d.\n", branchFrom);
                } else {
                    hondaCivicInventory -= quantity;
                    hondaCivicInventory += quantity;
                    printf("Transferring %d Honda Civic from branch %d to branch %d.\n", quantity, branchFrom, branchTo);
                }
            } else {
                printf("Error: Car not available at branch %d.\n", branchFrom);
            }
            break;
        case 3:
            if(branchFrom == 3) {
                if(quantity > fordMustangInventory) {
                    printf("Error: Insufficient inventory at branch %d.\n", branchFrom);
                } else {
                    fordMustangInventory -= quantity;
                    fordMustangInventory += quantity;
                    printf("Transferring %d Ford Mustang from branch %d to branch %d.\n", quantity, branchFrom, branchTo);
                }
            } else {
                printf("Error: Car not available at branch %d.\n", branchFrom);
            }
            break;
        default:
            printf("Error: Invalid car choice.\n");
            break;
    }
}

// Function to supply cars to branches with rebates
void supplyCars() {
    int branchChoice, carChoice;
    float rebatePercentage;
    
    printf("Supply Cars\n");
    printf("Enter branch to supply to (

// Global variables for inventory and prices
int toyotaCamryInventory = 10;
float TOYOTA_CAMRY_PRICE = 25000.0;

int hondaCivicInventory = 8;
float HONDA_CIVIC_PRICE = 22000.0;

int fordMustangInventory = 6;
float FORD_MUSTANG_PRICE = 50000.0;

// Function to transfer cars between branches
void transferCar() {
    int branchFrom, branchTo, carChoice, quantity;
    
    printf("Transfer Car\n");
    printf("Enter branch to transfer from (1-3): ");
    scanf("%d", &branchFrom);
    printf("Enter branch to transfer to (1-3): ");
    scanf("%d", &branchTo);
    
    if(branchFrom < 1 || branchFrom > 3 || branchTo < 1 || branchTo > 3) {
        printf("Error: Invalid branch choice.\n");
        return;
    }
    
    printf("Car Choices:\n");
    printf("1. Toyota Camry\n");
    printf("2. Honda Civic\n");
    printf("3. Ford Mustang\n");
    printf("Enter car choice (1-3): ");
    scanf("%d", &carChoice);
    
    if(carChoice < 1 || carChoice > 3) {
        printf("Error: Invalid car choice.\n");
        return;
    }
    
    printf("Enter quantity to transfer: ");
    scanf("%d", &quantity);
    
    switch(carChoice) {
        case 1:
            if(branchFrom == 1) {
                if(quantity > toyotaCamryInventory) {
                    printf("Error: Insufficient inventory at branch %d.\n", branchFrom);
                } else {
                    toyotaCamryInventory -= quantity;
                    toyotaCamryInventory += quantity;
                    printf("Transferring %d Toyota Camry from branch %d to branch %d.\n", quantity, branchFrom, branchTo);
                }
            } else {
                printf("Error: Car not available at branch %d.\n", branchFrom);
            }
            break;
        case 2:
            if(branchFrom == 2) {
                if(quantity > hondaCivicInventory) {
                    printf("Error: Insufficient inventory at branch %d.\n", branchFrom);
                } else {
                    hondaCivicInventory -= quantity;
                    hondaCivicInventory += quantity;
                    printf("Transferring %d Honda Civic from branch %d to branch %d.\n", quantity, branchFrom, branchTo);
                }
            } else {
                printf("Error: Car not available at branch %d.\n", branchFrom);
            }
            break;
        case 3:
            if(branchFrom == 3) {
                if(quantity > fordMustangInventory) {
                    printf("Error: Insufficient inventory at branch %d.\n", branchFrom);
                } else {
                    fordMustangInventory -= quantity;
                    fordMustangInventory += quantity;
                    printf("Transferring %d Ford Mustang from branch %d to branch %d.\n", quantity, branchFrom, branchTo);
                }
            } else {
                printf("Error: Car not available at branch %d.\n", branchFrom);
            }
            break;
        default:
            printf("Error: Invalid car choice.\n");
            break;
    }
}

// Function to supply cars to branches with rebates
void supplyCars() {
    int branchChoice, carChoice;
    float rebatePercentage;
    
    printf("Supply Cars\n");
    printf("Enter branch to supply to (

1-3): ");
    scanf("%d", &branchChoice);
    
    if(branchChoice < 1 || branchChoice > 3) {
        printf("Error: Invalid branch choice.\n");
        return;
    }
    
    printf("Car Choices:\n");
    printf("1. Toyota Camry\n");
    printf("2. Honda Civic\n");
    printf("3. Ford Mustang\n");
    printf("Enter car choice (1-3): ");
    scanf("%d", &carChoice);
    
    if(carChoice < 1 || carChoice > 3) {
        printf("Error: Invalid car choice.\n");
        return;
    }
    
    printf("Enter rebate percentage (0-100): ");
    scanf("%f", &rebatePercentage);
    
    if(rebatePercentage < 0 || rebatePercentage > 100) {
        printf("Error: Invalid rebate percentage.\n");
        return;
    }
    
    switch(carChoice) {
        case 1:
            if(branchChoice == 1) {
                printf("Error: Cannot supply cars to the same branch.\n");
            } else {
                if(toyotaCamryInventory == 0) {
                    printf("Error: No Toyota Camry available in inventory.\n");
                } else {
                    toyotaCamryInventory--;
                    float priceWithRebate = TOYOTA_CAMRY_PRICE * (1 - rebatePercentage/100);
                    printf("Supplying 1 Toyota Camry to branch %d with a rebate of %.2f%%. Price with rebate: $%.2f\n", branchChoice, rebatePercentage, priceWithRebate);
                }
            }
            break;
        case 2:
            if(branchChoice == 2) {
                printf("Error: Cannot supply cars to the same branch.\n");
            } else {
                if(hondaCivicInventory == 0) {
                    printf("Error: No Honda Civic available in inventory.\n");
                } else {
                    hondaCivicInventory--;
                    float priceWithRebate = HONDA_CIVIC_PRICE * (1 - rebatePercentage/100);
                    printf("Supplying 1 Honda Civic to branch %d with a rebate of %.2f%%. Price with rebate: $%.2f\n", branchChoice, rebatePercentage, priceWithRebate);
                }
            }
            break;
        case 3:
            if(branchChoice == 3) {
                printf("Error: Cannot supply cars to the same branch.\n");
            } else {
                if(fordMustangInventory == 0) {
                    printf("Error: No Ford Mustang available in inventory.\n");
                } else {
                    fordMustangInventory--;
                    float priceWithRebate = FORD_MUSTANG_PRICE * (1 - rebatePercentage/100);
                    printf("Supplying 1 Ford Mustang to branch %d with a rebate of %.2f%%. Price with rebate: $%.2f\n", branchChoice, rebatePercentage, priceWithRebate);
                }
            }
            break;
        default:
            printf("Error: Invalid car choice.\n");
            break;
    }
}

// Main function
int main() {
    int choice;
    while(1) {
        printf("\nCar Dealership Inventory System\n");
        printf("1. View Inventory\n");
        printf("2. Sell Car\n");
        printf("3. Transfer Car\n");
        printf("4. Supply Cars\n");
        printf("5. Exit\n");
        printf("Enter your choice (1-5): ");
        scanf("%d", &choice);
        
        switch(choice) {
            case 1:
                viewInventory();
                break;
            case 2:
                sellCar();
                break;
            case 3:
                transferCar();
                break;
            case 4:
                supplyCars();
                break;
            case 5:
                printf("Thank you for using the Car Dealership Inventory System. Exiting...\n");
                return 0;
            default:
                printf("Error: Invalid choice. Please try again.\n");
                break;
        }
    }
    return 0;
}                                                                                                                               

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Avatar image
Read by 1 person
Already have an account? Log in

Related questions

Weekly leaderboard

Start filling in the gaps now
Log in