This program is meant to find the model numbers in rental car company which where rented the highest number of days. I have one structre for all rentals records, one structure for all car stock records, and one sturcture to hold the results of the function & display them efficiantly. The problems I'm facing now are:

1. When I asign the rentals structure to the total_rental_time structure (line 78- 79), I get "left operand must be l-value"

2. When I sort the total_rental_time, the structure is sorted & I get unsorted results.

BTW: I have posted another version of this code under a different title, but didn’t get to solve it all at that session…

Code:#include <stdio.h> #include <stdlib.h> #define TOTAL_RENTALS 10 #define ALL_CARS 4 typedef enum areas {north = 1, center, south} areas; typedef struct { int model; areas area; int rental_length; int day_pay; int age; } rentals; rentals all_rentals[TOTAL_RENTALS] = { { 1111, north, 11, 20, 21 }, { 2222, south, 15, 25, 35 }, { 3333, center, 106, 23, 63 }, { 4444, north, 11, 25, 57 }, { 2222, center, 10, 23, 45 }, { 4444, center, 3, 20, 20 }, }; typedef struct{ int model; char mnfctr[20]; char model_name[15]; int stock; } car; car cars[ALL_CARS] = { { 1111, "Rols-Roys", "R-1", 010 }, { 2222, "Mercedes", "M-1", 020 }, { 3333, "Mercedes", "M-2", 057 }, { 4444, "Jajuar", "J-1", 103 } }; typedef struct { int ModelNo; int TotalTime; char MnfctrNm[20]; char ModelNm[15]; }total_rental_time_strct; total_rental_time_strct total_rental_time[TOTAL_RENTALS] ; int process[TOTAL_RENTALS] = { 0 }; void hi_rent_model(void); void title (void); int main(void) { hi_rent_model(); return 0; } void hi_rent_model(void) { int i, j,temp; total_rental_time_strct temp_rent; for(i = 0;i < TOTAL_RENTALS;i++) { if(!process[i]) { total_rental_time[i].TotalTime += all_rentals[i].rental_length; for(j = i+1;j < TOTAL_RENTALS;j++) { if(all_rentals[i].model == all_rentals[j].model) { total_rental_time[i].TotalTime += all_rentals[j].rental_length; process[j] = 1; } total_rental_time[i].ModelNo = cars[i].model; total_rental_time[i].MnfctrNm = cars[i].mnfctr; total_rental_time[i].ModelNm = cars[i].model_name; } } } for (i=0;i<TOTAL_RENTALS;++i) if(process[i]!=1) { for (j=i+1;j<TOTAL_RENTALS;++j) { if(process[j]!=1) { if (total_rental_time[i].TotalTime < total_rental_time[j].TotalTime) { temp=total_rental_time[j].TotalTime; total_rental_time[j].TotalTime=total_rental_time[i].TotalTime; total_rental_time[i].TotalTime=temp; temp_rent=total_rental_time[i]; total_rental_time[i]=total_rental_time[j]; total_rental_time[j]=temp_rent; } } } } for(i = 0;i < TOTAL_RENTALS;i++) { if(total_rental_time[i].TotalTime != 0) printf("Model %d had a total of %d days\n", total_rental_time[i].ModelNo, total_rental_time[i].TotalTime); } title(); printf ("\n %2d %17s %13s %8d\n ",cars[0].model, cars[0].model_name, cars[0].mnfctr, total_rental_time[i].TotalTime ); } void title (void) { puts ("============================================================\n\r"); puts ("model number | model name | manufacturer | total rental days\n\r"); puts ("============================================================\n\r"); }

TIA,

Ronen