Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help figuring out a problem with my code. The code runs fine but the variables are different then the ones I needed on a

Need help figuring out a problem with my code. The code runs fine but the variables are different then the ones I needed on a zybooks assignment. I've tried for hours but I can't wrap my head around the error messages I keep getting. Like it says I have variables unused but they are being used and I have variables that I'm almost positive I don't have like Car1 and Rental1. Could you please help me decipher them?

Error messages:

Compilation failed

image text in transcribed

carRental.c: In function testPassed: carRental.c:75:4: error: unknown type name Car Car car1; ^~~ carRental.c:75:4: note: use struct keyword to refer to the type carRental.c:76:4: error: unknown type name Rental Rental rental1; ^~~~~~ carRental.c:76:4: note: use struct keyword to refer to the type carRental.c:78:15: error: request for member make in something not a structure or union strcpy(car1.make, "make"); ^ carRental.c:79:15: error: request for member model in something not a structure or union strcpy(car1.model, "model"); ^ carRental.c:80:8: error: request for member carId in something not a structure or union car1.carId = 1; ^ carRental.c:81:8: error: request for member numDoors in something not a structure or union car1.numDoors = 4; ^ carRental.c:82:8: error: request for member rate in something not a structure or union car1.rate = 10.0; ^ carRental.c:84:11: error: request for member carId in something not a structure or union rental1.carId = 1; ^ carRental.c:85:11: error: request for member daysRenting in something not a structure or union rental1.daysRenting = 4; ^ carRental.c:86:18: error: request for member renterName in something not a structure or union strcpy(rental1.renterName, "renter1"); ^ carRental.c:76:11: warning: variable rental1 set but not used [-Wunused-but-set-variable] Rental rental1; ^~~~~~~ carRental.c:75:8: warning: variable car1 set but not used [-Wunused-but-set-variable] Car car1; ^~~~ carRental.c: In function main: carRental.c:106:12: warning: variable sizeR set but not used [-Wunused-but-set-variable] double sizeR=0; ^~~~~ carRental.c: In function addNewRental: carRental.c:349:17: warning: variable Cars set but not used [-Wunused-but-set-variable] struct Car *Cars[20]; ^~~~ carRental.c:348:34: warning: unused variable character [-Wunused-variable] char carMake[20], *Make[20], character; ^~~~~~~~~ carRental.c:348:24: warning: variable Make set but not used [-Wunused-but-set-variable] char carMake[20], *Make[20], character; ^~~~ carRental.c: In function findReservation: carRental.c:407:10: warning: unused variable areEqual [-Wunused-variable]

Here is the code in question

#include #include #include

struct Car //Inventory Info { int carId; char make[20]; char model[20]; int numDoors; double rate; };

struct Rental //Customer Info { char renterName[20]; int daysRenting; int carId; };

int createInventory ( struct Car *allCars );

int addNewCar (struct Car *allCars, int totalCars, int size);

int addNewRental (struct Car *allCars, int totalCars, struct Rental *allRentals, int totalRentals, int size );

int findCarIdByName (struct Car *allCars, int totalCars, char *carMake );

int findReservation (struct Rental *allRentals, int totalRentals, char *renterName );

int findCarById (struct Car *allCars, int totalCars, int carId );

void printAllRentals (struct Rental *allRentals, int totalRentals, struct Car *allCars, int totalCars );

void printCarInfo (struct Car *allCars, int totalCars, int CarId );

double getAverageRentalDays (struct Rental *allRentals, int totalRentals );

bool equalStrings (const char s1[], const char s2[]); bool equalInt (int i1, int i2); //void readLine (char buffer[]);

int main (void) {

int totalCars, totalRentals, sizeC,run, input, index, CarId; //char character; double avg=0; double sizeR=0; totalRentals=0; sizeC=0; input=0; totalCars=0; index=-1; char Name[20], Make[20]; struct Car allCars[20], *arr[20]; struct Rental allRentals[60], *Rentals[60];

for (int i=0;i

for (int i=0;i

do { //Updates pointers and variables for (int i=0;i

for (int i=0;i

for (int i=0;i

//Menu Display and Input. printf(" Menu "); printf("---- "); printf("1: Add new car to the inventory "); printf("2: Make a reservation "); printf("3: Find a reservation using renter name and print it to the screen "); printf("4: Print all rental information to the screen "); printf("5: Print car information to the screen of a selected car using the make of the car to search the inventory "); printf("6: Calculate and print average number of days rented "); printf("7: Exit program "); scanf(" %i",&input);

switch (input) { //Add a new car to the inventory case (1): { for (int i=0;i

//Make a new reservation case (2): { for (int i=0;i

//Find reservation using renter name and print it to the screen case (3): { printf("Enter the renter's name without spaces: "); //gets( Name); scanf(" %s",Name);

index=findReservation ( *Rentals, totalRentals, Name ); if (index==-1) printf("The reservation that you have requested does not exist. "); else { printf(" +----------------------------------------------------------------------------------------------- "); printf("| Renter Name: %s\t Days Renting: %i ",allRentals[index].renterName,allRentals[index].daysRenting); index=findCarById ( *arr, totalCars, allRentals[index].carId ); printf("| CarId: %i\t Make: %s\t Model: %s\t # Doors: %i\t Rental Rate: $%.2lf ",allCars[index].carId,allCars[index].make,allCars[index].model,allCars[index].numDoors,allCars[index].rate); printf("+----------------------------------------------------------------------------------------------- "); } break; }

//Print all rental information case (4): { printAllRentals (*Rentals, totalRentals, *arr, totalCars); break; } //Prints car information that matches the CarId. case (5): { printf("Enter the make of the car you would like to find without spaces: "); scanf(" %s",Make); CarId=findCarIdByName( *arr, totalCars, Make); printCarInfo (*arr, totalCars, CarId); break; } //Gets average days rented for all reservations. case (6): { avg=getAverageRentalDays (*Rentals, totalRentals); printf("The average days renting is: %.2lf",avg); break; } case (7): { run=-1; break; } } run++; }while (run>0); return 0; }

// createInventory() initializes the original inventory of cars in the first three slots of allCars[] int createInventory (struct Car *allCars) { allCars[0].carId=1234; allCars[0].make[0]='V'; allCars[0].make[1]='W'; allCars[0].make[2]='\0'; allCars[0].model[0]='G'; allCars[0].model[1]='o'; allCars[0].model[2]='l'; allCars[0].model[3]='f'; allCars[0].model[4]='\0'; allCars[0].numDoors=2; allCars[0].rate=66.00; allCars[1].carId=2241; allCars[1].make[0]='F'; allCars[1].make[1]='o'; allCars[1].make[2]='r'; allCars[1].make[3]='d'; allCars[1].make[4]='\0'; allCars[1].model[0]='F'; allCars[1].model[1]='o'; allCars[1].model[2]='c'; allCars[1].model[3]='u'; allCars[1].model[4]='s'; allCars[1].model[5]='\0'; allCars[1].numDoors=4; allCars[1].rate=45.00; allCars[2].carId=3445; allCars[2].make[0]='B'; allCars[2].make[1]='M'; allCars[2].make[2]='W'; allCars[2].make[3]='\0'; allCars[2].model[0]='X'; allCars[2].model[1]='3'; allCars[2].model[3]='\0'; allCars[2].numDoors=4; allCars[2].rate=128.00; printf("+--------------------------------------------------------------------------------------------------------"); printf(" | CarId: %i\t Make: %s\t Model: %s\t # Doors: %i\t Rental Rate: $%.2lf ",allCars[0].carId,allCars[0].make,allCars[0].model,allCars[0].numDoors,allCars[0].rate); printf("+--------------------------------------------------------------------------------------------------------"); printf(" | CarId: %i\t Make: %s\t Model: %s\t # Doors: %i\t Rental Rate: $%.2lf ",allCars[1].carId,allCars[1].make,allCars[1].model,allCars[1].numDoors,allCars[1].rate); printf("+--------------------------------------------------------------------------------------------------------"); printf(" | CarId: %i\t Make: %s\t Model: %s\t # Doors: %i\t Rental Rate: $%.2lf ",allCars[2].carId,allCars[2].make,allCars[2].model,allCars[2].numDoors,allCars[2].rate); printf("+--------------------------------------------------------------------------------------------------------"); printf(" These cars have been added to your inventory. "); return 3; }

//Option #1 "Add new car to inventory." Returns the number of cars in the inventory.

int addNewCar (struct Car *allCars, int totalCars, int size) { if (size==19) return totalCars; else { size++; printf("Enter the CarId #: "); scanf(" %i",&allCars[size].carId); printf("Enter the make without spaces: "); scanf(" %s",allCars[size].make); printf("Enter the model without spaces: "); scanf(" %s",allCars[size].model); printf("Enter the number of doors: "); scanf(" %i",&allCars[size].numDoors); printf("Enter the rental rate in $: "); scanf(" %lf",&allCars[size].rate); printf("+-----------------------------------------------------------------------------------------------"); printf(" | CarId: %i\t Make: %s\t Model: %s\t # Doors: %i\t Rental Rate: $%.2lf ",allCars[size].carId,allCars[size].make,allCars[size].model,allCars[size].numDoors,allCars[size].rate); printf("+----------------------------------------------------------------------------------------------- "); totalCars++; } return totalCars; }

//Option #2 "Make a new reservation." Returns the number of total rentals.

int addNewRental (struct Car *allCars, int totalCars, struct Rental *allRentals, int totalRentals, int size) { int Id=-1; int index; char carMake[20], *Make[20], character; struct Car *Cars[20]; if (size==59) { return 60; } else { for (int run=1;run>0;run++) { printf("Enter the renter's name without spaces: "); scanf(" %s",allRentals[size].renterName);

printf("Enter the number of days renting: "); scanf(" %i",&allRentals[size].daysRenting); printf("Enter the make of the car without spaces: "); scanf(" %s",carMake); for (int i=0;i

for (int i=0;i

return -1; }

//Called by Option #4, and 5. Finds car inventory information by CarId. Returns the array index as an integer. int findCarById (struct Car *allCars, int totalCars, int carId) { for (int i=0;i

//Option #4 Prints all rental information. No return value. void printAllRentals (struct Rental *allRentals, int totalRentals, struct Car *allCars, int totalCars) { int index; printf("+----------------------------------------------------------------------------------------------- "); for (int i=0;i

//Option #5 Prints the car information for the car the matches the CarId. void printCarInfo (struct Car *allCars, int totalCars, int CarId) { int index=findCarById (allCars, totalCars, CarId); printf(" +----------------------------------------------------------------------------------------------- "); printf("| CarId: %i\t Make: %s\t Model: %s\t # Doors: %i\t Rental Rate: $%.2lf ",allCars[index].carId,allCars[index].make,allCars[index].model,allCars[index].numDoors,allCars[index].rate); printf("+----------------------------------------------------------------------------------------------- "); return; }

//Option #6 Computes average days rented for all reservations. Returns the product as a double. double getAverageRentalDays (struct Rental *allRentals, int totalRentals) { double totalDays=0; for (int i=0;i

//Compares strings for equality & returns T/F. bool equalStrings (const char s1[], const char s2[]) { int i=0; bool areEqual;

while( s1[i]==s2[i] && s1[i]!='\0' && s2[i]!='\0' ) i++; if (s1[i]=='\0'&&s2[i]=='\0') areEqual=true; else areEqual=false; return areEqual; }

//Compares integers for equality & returns T/F. bool equalInt (int i1, int i2) { bool areEqual; if (i1==i2) areEqual=true; else areEqual=false; return areEqual; }

carRental.c: In function 'main': carRental.c:49:12: warning: variable 'sizeR' set but not used [-Wunused-but-set-variable] double sizeR 0 carRental.c: In function 'addNewRental' carRental.c:292:17: warning: variable 'Cars' set but not used I-Wunused-but-set-variable] struct Car *Cars [20]: carRental.c:291:34: warning: unused variable character' [-Wunused-variable] char carMake [20], *Make [20], character carRental.c:291:24: warning: variable 'Make' set but not used [-Wunused-but-set-variable] char carMake [20], *Make [20], character; carRenta ndReservation' carRental.c:350:10: warning: unused variable 'areEqual' [-Wunused-variable] 1.c: In function fi bool areEqual-o

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

5 0 8 .

Answered: 1 week ago