This task will be a car dealership where you'll help the user find the car(s) they want. This program should keep going until the user either decides to not continue with the purchase, or the purchase is complete, and no more order is being processed.

You will need 3 structs to store:

  • client information
  • order information
  • used_car information

Each struct would have the following fields:

struct used_car
{
int carID;
char brand[length];
char make[length];
int year;
int mileage;
float price;
};

struct order
{
int numCosigned;
int carID;
float pricePerPerson;
};

struct client
{
char firstName[length];
char lastName[length];
bool isEmployed;
int creditScore;
};

global variables:

  • Create an array of struct used_car and add some cars in there. I put 4 cars. You can do as many as you want (at least 3).
  • Make sure to put the struct definition above the array creation, otherwise, it won't work.
    • This is similar to you trying to call a function X that's not declared above of main or any other function that calls X.

main():

  • Print a welcome message.
  • Call a function that utilize all the cars available (from array created above) and print them, so the client knows what options they have.
  • Ask them to choose the which car they want. They can input their answer based on the carID field from available_car struct.
    • Make sure to check for invalid answers. Ask for reinput until it's valid.
    • I made my ID from 1->N.
      • You can tell them to input 0 if they don't want to buy anything.
      • If this is the case, write some message and quit the program.
  • Ask the user if they will be the sole owner or will they cosign and save that info into order structure.
    • We assume that if there are 2 co-signers, each will pay 50%, 3 co-signers would be 33.33% each, and so on
  • Print the price for the car that they have chosen, calculate how much EACH cosigner has to pay, and ask them if you are okay with this price and would like to process
    • If they answer No, write some message and quit the program.
    • If they answer Yes,
      • call another function to get the co-signers information (struct client)
      • when done getting the info, call another function to print back all the clients information
      • you can also print the price per person in the end when printing out each person's cost. Its up to you.

other functions (it' up to you to have more functions, Im giving the 3 required functions. Doesnt have to be exactly the same. This is a guide.):

  • printCars() function:
    • prints all the used cars the dealership have from the global array.
  • getClientInfo() function (or whatever you want to call it):
    • take an order struct
    • create an array of struct client.
    • loop through each client and get their information (name, creditScore,) and save the info in the struct client array.
    • call printClientInfo() function to print back the information after.

(You should not print the information right after the scanning the information, it should be done at the end and all the passengers info are printed together).

  • printClientInfo() function (or whatever you want to call it):
    • take an array of struct client
    • loop through each client and print out their information

Outputs

Run 1: Quit when input 0 for carID

Welcome to ECE131 Dealership.
Now, are we looking for (U)sed or (N)ew car: u
Cool! I got you. Got it! Here are the used cars info we have.

Car ID: 1. 2013 Honda Accord. Mileage: 117121. Cost: $15234.56
Car ID: 2. 2022 Ford Mustang GT. Mileage: 100. Cost: $55000.99
Car ID: 3. 2008 Jeep Liberty. Mileage: 130000. Cost: $5677.87
Car ID: 4. 2019 Tesla X. Mileage: 24000. Cost: $84000.00

Have you chosen the car you like? Enter the carID (choose 0 if you want to quit): 0
See you again soon hopefully. Bye now.

Run 2: Reinput when carID is invalid, and stop when Clients say not OK with the Price

Welcome to ECE131 Dealership.
Now, are we looking for (U)sed or (N)ew car: u
Cool! I got you. Got it! Here are the used cars info we have.

Car ID: 1. 2013 Honda Accord. Mileage: 117121. Cost: $15234.56
Car ID: 2. 2022 Ford Mustang GT. Mileage: 100. Cost: $55000.99
Car ID: 3. 2008 Jeep Liberty. Mileage: 130000. Cost: $5677.87
Car ID: 4. 2019 Tesla X. Mileage: 24000. Cost: $84000.00

Have you chosen the car you like? Enter the carID (choose 0 if you want to quit): 5
You gave me an invalid car ID. Please input again: 3
Thank you. Last question before we can start the process. How many people buying this car. Enter here: 2
Great. So you chose carID 3.
The cost of this car will be 5477.87. Would you be OK with that? Enter here (Y/N): n
It's sad to see you go. Bye.

Run 3: Didn't want to buy the car last minute. Quit!

Welcome to ECE131 Dealership.
Now, are we looking for (U)sed or (N)ew car: u
Cool! I got you. Got it! Here are the used cars info we have.

Car ID: 1. 2013 Honda Accord. Mileage: 117121. Cost: $15234.56
Car ID: 2. 2022 Ford Mustang GT. Mileage: 100. Cost: $55000.99
Car ID: 3. 2008 Jeep Liberty. Mileage: 130000. Cost: $5677.87
Car ID: 4. 2019 Tesla X. Mileage: 24000. Cost: $84000.00

Have you chosen the car you like? Enter the carID (choose 0 if you want to quit): 4
Thank you. Last question before we can start the process. How many people buying this car. Enter here: 2
Great. So you chose carID 4.
The cost of this car will be 84000.00. Would you be OK with that? Enter here (Y/N): Y
Great! We'll start getting the cosigners information then!

You have 2 people buying this car. I'll process them one by one.

Processing Cosigner #1. Please enter first name followed by Last Name: first name
Thank you. Do you currently have a job (Y)es or (N)o: y
Enter your credit score: 765
Thank you! You're set :)

Processing Cosigner #1. Please enter first name followed by Last Name: last name
Thank you. Do you currently have a job (Y)es or (N)o: n
Enter your credit score: 222
Thank you! You're set :)
Everything looks good. The price per person remains at 42000.00.
Do you want to confirm and finish the purchase (Y/N): n
Come back next time when you change your mind. Bye.
Thank you! You're set :)

Run 4: Reinput when carID is invalid, purchase the car, and start a new order

Welcome to ECE131 Dealership.
Now, are we looking for (U)sed or (N)ew car: u
Cool! I got you. Got it! Here are the used cars info we have.

Car ID: 1. 2013 Honda Accord. Mileage: 117121. Cost: $15234.56
Car ID: 2. 2022 Ford Mustang GT. Mileage: 100. Cost: $55000.99
Car ID: 3. 2008 Jeep Liberty. Mileage: 130000. Cost: $5677.87
Car ID: 4. 2019 Tesla X. Mileage: 24000. Cost: $84000.00

Have you chosen the car you like? Enter the carID (choose 0 if you want to quit): 5
You gave me an invalid car ID. Please input again: 6
You gave me an invalid car ID. Please input again: 7
You gave me an invalid car ID. Please input again: 3
Thank you. Last question before we can start the process. How many people buying this car. Enter here: 2
Great. So you chose carID 3.
The cost of this car will be 5677.87. Would you be OK with that? Enter here (Y/N): Y
Great! We'll start getting the cosigners information then!

You have 2 people buying this car. I'll process them one by one.

Processing Cosigner #1. Please enter first name followed by Last Name: Jade Valentino
Thank you. Do you currently have a job (Y)es or (N)o: n
Enter your credit score: 123
Thank you! You're set :)

Processing Cosigner #1. Please enter first name followed by Last Name: Lily Smith
Thank you. Do you currently have a job (Y)es or (N)o: Y
Enter your credit score: 666
Thank you! You're set :)
Everything looks good. The price per person remains at 2838.94.
Do you want to confirm and finish the purchase (Y/N): Y
PROCESSING ....
Awesome!! I have purchased the cars. Here's the information about the buyers of your car. You have a wonderful time.

Client #1: Jade Valentino. Credit Score: 123. Employed: 70.
Client #2: Lily Smith. Credit Score: 666. Employed: 89.

Thank you for choosing our agency. Would you like to input another purchase? Enter here (Y/N): Y
Welcome to ECE131 Dealership.
Now, are we looking for (U)sed or (N)ew car: u
Cool! I got you. Got it! Here are the used cars info we have.

Car ID: 1. 2013 Honda Accord. Mileage: 117121. Cost: $15234.56
Car ID: 2. 2022 Ford Mustang GT. Mileage: 100. Cost: $55000.99
Car ID: 3. 2008 Jeep Liberty. Mileage: 130000. Cost: $5677.87
Car ID: 4. 2019 Tesla X. Mileage: 24000. Cost: $84000.00

The previous task asks you to help and purchase used cars. We can expand to include new cars as well. Your structs would need more information as below:

struct used_car
{
int carID;
char brand[length];
char make[length];
int year;
int mileage;
float price;
};

struct new_car
{
int carID;
char brand[length];
char make[length];
float waitTime;
float price;
int minCred;
bool needEmployment;
};

struct order
{
int numCosigned;
int carID;
float pricePerPerson;
int min_creds;
char need_employed;
bool buyNew;
int verifiedCosigners;
};

struct client
{
char firstName[length];
char lastName[length];
bool isEmployed;
int creditScore;
};

Assumptions:

  • Ask the client first to choose if they want to buy new or used car
    • Depends on what they answer, use proper struct.
  • All car purchases require employee and minimum credit score check.
  • If 1 or more people have not met the 2 requirements above, you should give them the option of skipping these people and re-adjust the price of the co-signers.
    • If they don't want to, exit the program
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.