64,651
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <conio.h>
using namespace std;
enum Weapons{Pistol, Shotgun, MachineGun, Bazooka, RocketLaucher};
int main(){
cout <<"Which weapon do you want? "<< endl;
cout <<"1) Pistal" <<endl;
cout <<"2) Shotgun" <<endl;
cout <<"3) Machinegun" <<endl;
cout <<"4) Bazooka" <<endl;
cout <<"5) RocketLaucher" <<endl <<endl;
int weapon_choice;
cin >> weapon_choice;
weapon_choice--;//这里带两个减号是什么意思?
switch(weapon_choice){
case Pistol:
cout << "You have chosen a Pistol";
break;
case Shotgun:
cout << "You have chosen a Shotgun";
break;
case MachineGun:
cout << "You have chosen a MachineGun";
break;
case Bazooka:
cout << "You have chosen a Bazooka";
break;
case RocketLaucher:
cout << "You have chosen a RocketLaucher";
break;
}
getch();
return 0;
}
enum Weapons{Pistol, Shotgun, MachineGun, Bazooka, RocketLaucher};
// 这个枚举,让:Pistol = 0, Shotgun = 1, MachineGun = 2, Bazooka = 3, RocketLauncher = 4
int weapon_choice;
cin >> weapon_choice;
weapon_choice--; // 如果你输入的是1, 那么这句话执行完成后weapon_choice就等于0
switch(weapon_choice){
case Pistol: // 所以如果你前面输入的是1,就会选择执行这个case
cout << "You have chosen a Pistol";
break;
case Shotgun: // 所以如果你前面输入的是2,就会选择执行这个case
cout << "You have chosen a Shotgun";
break;
case MachineGun: // 所以如果你前面输入的是3,就会选择执行这个case
cout << "You have chosen a MachineGun";
break;
case Bazooka: // 所以如果你前面输入的是4,就会选择执行这个case
cout << "You have chosen a Bazooka";
break;
case RocketLaucher: // 所以如果你前面输入的是5,就会选择执行这个case
cout << "You have chosen a RocketLaucher";
break;
}
cout <<"1) Pistal" <<endl;
cout <<"2) Shotgun" <<endl;
cout <<"3) Machinegun" <<endl;
cout <<"4) Bazooka" <<endl;
cout <<"5) RocketLaucher" <<endl <<endl;