What is wrong? "#include " "#include " "int main()" { "float car_weight, max_weight"; int number_of_

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

What is wrong? "#include " "#include " "int main()" { "float car_weight, max_weight"; int number_of_

Post by answerhappygod »

What is wrong?
"#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;
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply