我在寫關於switch語句的基本程序。 5個選項菜單,如果使用輸入無效號碼,應再次提示用戶進行選擇(範圍從1-5)。在這裏我得到了什麼至今:switch語句C++ [默認部分]
#include <iostream>
#include "Menu.h"
using namespace std;
void Menu::inputChoices()
{
int choice;
cout << "IHCC Computer Science Registration Menu" << endl;
cout << "1. Welome to Computer Programming in C++" << endl;
cout << "2. Welcome to Java Programming" << endl;
cout << "3. Welcome to Android Programming" << endl;
cout << "4. Welcome to iOS Programming" << endl;
cout << "5. Exit" << endl;
cout << "\nEnter your selection: " << endl;
while ((choice = cin.get()) != EOF)
{
switch (choice)
{
case '1':
cout << "Welcome to Computer Programming in C++" << endl;
break;
case '2':
cout << "Welcome to Java Programming" << endl;
break;
case '3':
cout << "Welcome to Android Programming" << endl;
break;
case '4':
cout << "Welcome to iOS Programming" << endl;
break;
case '5':
cout << "Exiting program" << endl;
break;
default:
cout << "Invalid input. Re-Enter your selection: " << endl;
}
}
}
該項目有3個文件,這是源文件。我的問題是,當我輸入一個數字在(1-5)的範圍內,開關的默認部分仍然顯示。我只想顯示我的選擇。任何人都可以幫助我!非常感謝您
你好,如果其中一個答案幫助你解決了你的問題,請檢查它是否正確。如果沒有,我們可以嘗試進一步幫助你。 – usandfriends 2015-05-29 00:59:22