我需要一些代码帮助,我希望它做的是能够让电脑"嘟嘟"使用报警功能,即:\一个,但我不知道如何实现它,这样用户可以选择多少次使用switch语句时会发出哔哔声,真的会感谢所有的帮助.
#include <iostream>
using namespace std;
int main()
{
int x;
int y;
cout << "Do you want to make your computer beep" << endl;
cin >> x;
if (x == 'y' || x == 'Y')
{
cout << "How many beeps do you want" << endl;
switch (y)
{
// This is the part i'm stuck on!!!
}
}
cin.ignore();
cin.get();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
您可能不应该使用开关来执行此操作,否则您将不得不为他们可能选择的每个数字编写一个案例.这里应该使用for循环:
int n;
cout << "How many beeps? " << endl;
cin >> n;
for (int i = 0; i < n; i++) {
cout << "\a";
}
Run Code Online (Sandbox Code Playgroud)