我不知道如何做到这一点,所以当我在testSelection中输入我的选择以使其指向功能测试时。我该怎么做?它不应该去那里吗?
#include <iostream>
using namespace std;
int test (int testSelection);
int main()
{
int testSelection;
cout << "Welcome to the pizza place!" << endl;
cout << "Choose 1 for pizza or 2 for drinks: ";
cin >> testSelection;
return 0;
}
int test (int testSelection)
{
if (testSelection== 1)
{
cout << "select your Pizza" << endl;
}
if (testSelection== 2)
{
cout << "Please select your drink" << endl;
}
else
cout << "test";
return 0;
}
最佳答案
您需要调用该函数...
cin >> testSelection;
测试(testSelection);
基本上,您已经编写了一个函数定义int test(int testSelection){... code ...},但是,它只是休眠代码,直到您通过调用它来调用它为止。
关于c++ - Cin和指向功能选择,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7693131/