#include <iostream>
using namespace std;
void show_menu()
{
cout << "Welcome" << endl;
cout << "1) Match line-up" << endl;
cout << "2) Match result" << endl;
cout << "3) Quit program" << endl;
}
int selection()
{
cout << "Select option" << endl;
int input;
cin >> input;
return input;
}
int process (int x)
{
switch(x)
{
case 1:
cout << "Line ups" << endl;
case 2:
cout << "Arsenal 3 - Crystal Palace 0" << endl;
case 3:
cout << "Quitting" << endl;
default:
cout << "Select Option1" << endl;
}
}
int main()
{
show_menu();
int input2 = selection();
process(input2);
return 0;
}
所以這是一些菜單和輸入選項的代碼,我寫它作爲subroutins一個運動,但在下面我的功能有,我解決throgh問題一些trile和arror,但我仍然沒有得到它。C++函數參數:將數據傳遞給子程序和變量
int process (int x)
{
switch(x)
{
case 1:
cout << "Line ups" << endl;
case 2:
cout << "Arsenal 3 - Crystal Palace 0" << endl;
case 3:
cout << "Quitting" << endl;
default:
cout << "Select Option1" << endl;
}
}
爲什麼我需要變量(int x)才能使這個函數工作? 我有一種感覺,我不明白一些非常基本的東西。請幫助)
爲了弄清楚你不明白的東西:爲什麼你有一種感覺,你不需要變量'x'? –
或者有所不同:代碼在你的理解中應該如何表現?爲什麼? –