Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When I put my code, I only got 75points. I guess that's because my while condition has something problem. Help me to write it c

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

When I put my code, I only got 75points. I guess that's because my while condition has something problem.

Help me to write it c code.

PD1 E-learning Wrong Answer (75/100) CLOSE A UPLOAD FILE O UPLOAD FROM GITHUB A UPLOAD FROM GITLAB HAPPY PARTY TRAIN 1 int fire(struct Car* head) { 2 int count=0; 3 Medium AC Ratio: 13.9% (255/1835) 4 #lf/else #Loop #Pointers #Struct 5 head = head->next; while(head->next!=NULL) { One tourist train is departing, and it's powered by a steam locomotive. Unfortunately, when passengers holding a party in cars, 7 8 9 the coal used as fuel in the back of the locomotive is on fire, burning red. 10 11 And every car contains different number of flammable items. if(head->passenger>=head->flammable) return count; else{ head->next->passenger += head->passenger; head = head->next; count++; } When passengers see the fire coming, they try to move these items to prevent fire burn to their car. 12 13 14 15 If number of peoples in the car >= amounts of flammable items, fire will not burn to this car and the following cars. 16 17 } return count; Otherwise, passengers in this car will evacuate to the the next car. 18 } Now you know the number of people & flammable items in each car, Please calculate how many cars will be burnt by fire. This train is represented with linked-list, each Car node's next will point to the next car , last cat will points to NULL Compile Message Head car Car 1 Car 2 passenger passenger SUBMIT Send Testing Submission X flammable flammable next next next Your code will be verified by the main file below #include #include struct Car { int passenger; int flammable; struct car *next; }; void attachcar(struct car *head, int passenger, int flammable) { struct Car *curr = head; while(curr->next) curr = curr->next; 1/ Find the end of the train struct Car #newcar = malloc(sizeof(struct Car)); // Make a new car newcar->passenger = passenger; 1/ Let passengers in newcar->flammable = flammable; // Load flammable items newcar->next = NULL; // This is the last car curr->next = newcar; // Attach new car to the trai int fire(struct car *head); int main(int argc, char *argv[]) { int cars; int human[13], moeru[13]; struct Car head; head.next = NULL; // passenger & flammable for head in useless scanf("%d", &cars); for (int i = 0; i

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_2

Step: 3

blur-text-image_3

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

Probabilistic Databases

Authors: Dan Suciu, Dan Olteanu, Christopher Re, Christoph Koch

1st Edition

3031007514, 978-3031007514

More Books

Students also viewed these Databases questions

Question

3. Existing organizations and programs constrain behavior.

Answered: 1 week ago