Page 1 of 1

HOW WOULD THE CODE LOOK CORRECTLY? #include " "#include " "int main()" { "float car_weight, max_weig

Posted: Mon Jun 06, 2022 5:42 pm
by answerhappygod
HOW WOULD THE CODE LOOK CORRECTLY?
#include <stdio.h> "
"#include <stdlib.h>"
"int main()"
{
"float car_weight, max_weight";
int number_of_cars;
float *weight_ptr;


printf("Enter the maximum weight the car can hold: ");
scanf("%f", &max_weight);

printf("Enter the number of cars: ");
scanf("%d", &number_of_cars);

weight_ptr = (float*)malloc(number_of_cars * sizeof(float));

"for" ("int i = 0"; "i" < "number_of_cars; i++")
{
"printf"("Enter the car %d weight: ", i + 1);
scanf("%f", &car_weight);

if (car_weight > max_weight)
{
printf("The car %d is too heavy.\n", i + 1);
}
else
{
weight_ptr = car_weight;
}
}

printf("The cars that are within the weight limit are: ");
"for" ("int i = 0"; "i" < "number_of_cars; i++")
{
if (weight_ptr > 0)
{
printf("%d ", i + 1);
}
}

free(weight_ptr);

return 0;
}