注册 登录
编程论坛 C++教室

上学第一个星期的测验题 : 错在哪里

kaneqeqeq 发布于 2007-07-14 19:41, 650 次点击
#include <iostream>

// Prototypes
void DisplayMenu();
int GetSelection();

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
// Display the menu.
DisplayMenu();

// Get the menu selection.
int selection;
selection = GetSelection();

// Select the matching process
switch (selection)
{
case 1:
std::cout << "Processing Receivables" << std::endl;
break;
case 2:
std::cout << "Processing Payables" << std::endl;
break;
case 3:
std::cout << "Quitting" << std::endl;
break;
default:
std::cout << "\aInvalid selection" << std::endl;
break;
}

return 0;
}

////////////////////////////////////////
// Display a menu.
////////////////////////////////////////
void DisplayMenu()
{
std::cout << "--- Menu ---" << endl;
std::cout << "1=Receivables" << endl;
std::cout << "2=Payables" << endl;
std::cout << "3=Quit" << endl;
}

////////////////////////////////////////
// Read a menu selection from the
// keyboard.
////////////////////////////////////////
int GetSelection()
{
int selection;
std::cout << "Enter Selection: ";
std::cin >> selection;

return selection;
}
3 回复
#2
一番宝瓶2007-07-14 20:02

既然你不想用using namespace std; 把整个标准命名空间展开的话,DisplayMenu() 函数里的endl 应该为std::endl

#3
kaneqeqeq2007-07-14 20:06
我終於知道 using namespace std 用法了,你教得好好 !!

還有,你的圖片很有 style !! XD

[此贴子已经被作者于2007-7-14 20:07:22编辑过]

#4
kaikai199582007-07-14 23:47
厉害!我也学到了点东西.谢谢!
1