帮我用c+ 写一个能直接运行的填方挖方代码
时间: 2023-12-14 22:36:58 浏览: 26
好的,下面是一个可以直接运行的填方挖方代码,需要输入填方还是挖方以及要填或挖的体积:
```
#include <iostream>
using namespace std;
int main() {
int choice, volume, width, length, height;
cout << "请选择操作:\n1.填方\n2.挖方\n";
cin >> choice;
switch(choice) {
case 1:
cout << "请输入填方体积:";
cin >> volume;
cout << "请输入工地长度、宽度、高度:";
cin >> length >> width >> height;
if(volume > length * width * height) {
cout << "填方体积过大,无法完成!\n";
} else {
int remaining_volume = length * width * height - volume;
cout << "还需要填方体积:" << remaining_volume << endl;
}
break;
case 2:
cout << "请输入挖方体积:";
cin >> volume;
cout << "请输入工地长度、宽度、高度:";
cin >> length >> width >> height;
if(volume > length * width * height) {
cout << "挖方体积过大,无法完成!\n";
} else {
int remaining_volume = volume - length * width * height;
cout << "还需要挖方体积:" << remaining_volume << endl;
}
break;
default:
cout << "无效的选项!\n";
break;
}
return 0;
}
```
希望能对你有所帮助!