能帮我用C++写一段自动泊车代码吗
时间: 2023-02-27 12:47:05 浏览: 122
当然,很高兴为您写一段自动泊车代码。这是一段简单的代码示例:
```
#include <stdio.h>
int main()
{
int parking_space = 0;
int command = 0;
int car_count = 0;
printf("Welcome to the parking lot system\n");
printf("Please input the number of parking spaces: ");
scanf("%d", &parking_space);
while (1)
{
printf("\nInput 1 to park a car\n");
printf("Input 2 to retrieve a car\n");
printf("Input 0 to exit\n");
scanf("%d", &command);
if (command == 1)
{
if (car_count >= parking_space)
{
printf("The parking lot is full\n");
}
else
{
printf("The car has been parked\n");
car_count++;
}
}
else if (command == 2)
{
if (car_count <= 0)
{
printf("The parking lot is empty\n");
}
else
{
printf("The car has been retrieved\n");
car_count--;
}
}
else if (command == 0)
{
break;
}
else
{
printf("Invalid input\n");
}
}
return 0;
}
```
希望这段代码对您有所帮助!
阅读全文