|
If user input 3, 8, 5, -1
after that display 3, 8, 5, -1
and display 3, 5, 8
박지훈.임프 님이 쓰신 글 :
: 임펠리테리입니다.
:
: "입력후 디스플레이가 안된다" 라고 하셨는데, 뭐가 디스플레이되기를 바라신 건지 모르겠네요.
: 컴파일해서 실행해보니 0부터 3까지의 메뉴가 뜨고 1번을 선택할 경우 숫자 리스트를 입력받던데,
: for 문으로 입력받은 숫자를 하나하나 루프를 돌 때마다 메뉴를 다시 출력시키는군요.
: 매번 사용자 입력을 받기 때문에 잘 모를 수도 있습니다만, 로직이 잘못되어서 재귀호출로 들어가는군요.
:
: 출력되길 바란 결과가 무언지는 알려주셔야 답변을 하겠죠?
: 보여주신 소스에 무언가를 출력하려는 시도가 전혀 없어서 님의 깊으신 뜻을 전혀 짐작할 수가 없군요. ^^;;
:
: 그럼 이만...
:
:
: kim 님이 쓰신 글 :
: : 무엇이 잘못인지 알려주세요.
: : 숫자 입력후에 디스플레이가 안돼요.
: :
: : #include <iostream.h>
: : #include <ctype.h>
: : void DisplayIntroduction(void);
: : void DisplayMainMenu(void);
: : int GetMenuSelection(int Min, int Max);
: : void MenuSelection(int Select);
: : int GetIntegers(void);
: : void DisplayStatistics (void);
: :
: :
: : void Pause (void);
: : const int
: : MAX_NBR_INTEGERS = 30;
: :
: : void main(void)
: : {
: : //int
: : // Nums[MAX_NBR_INTEGERS] = {0},
: : // NbrInteger = 0;
: : DisplayIntroduction();
: : //GetIntegers();
: : }
: : void DisplayIntroduction(void)
: : {
: : cout <<"This program calculates the mean, median, and mode"
: : <<"\nof up to 30 integers (each between 0 and 9)";
: : DisplayMainMenu();
: : }
: : void DisplayMainMenu(void)
: : {
: : cout <<"\n\nMain Menu"
: : <<"\n\t1. Enter integers"
: : <<"\n\t2. Display statistics"
: : <<"\n\t3. Clear integers"
: : <<"\n\t0. Exit"
: : << "\n Choose an option ==> : ";
: : GetMenuSelection(0, 3);
: : }
: : int GetMenuSelection (int Min, int Max)
: : {
: : int
: : Select = Min - 1;
: :
: : cin >> Select;
: : while((Select < Min)||(Select > Max))
: : {
: : cout << "\n ********** Error ********** !" << endl
: : << " Please enter number in range 0 to 3 > ";
: : cin >> Select;
: : }
: : MenuSelection(Select);
: : return Select;
: :
: : }
: : void MenuSelection(int Select)
: : {
: : int
: : Nums[30];
: : if (Select == 1)
: : {
: : GetIntegers();
: : }
: : else if (Select == 2)
: : {
: : DisplayStatistics();
: : for (int i = 0; i < MAX_NBR_INTEGERS; i++ )
: : cout << Nums[i] << " ";
: :
: : }
: : }
: : int GetIntegers(void)
: : {
: : int
: : Nums[MAX_NBR_INTEGERS];
: : cout <<"\nEnter a string of integers (each between 0 and 9),ending in -1."
: : <<"\nAny more than 30 integers will be ignored."
: : <<"\nExample: 9 3 3 4 1 1 7 2 -1\n";
: : for (int i = 0; i < MAX_NBR_INTEGERS; i++ )
: : {
: : cin >> Nums[i];
: : if ((Nums[i] >9)||(Nums[i] < -1))
: : {
: : cout << "\nERROR:An invalid integer has been ignored: ";
: : cout << Nums[i]
: : << "\n";
: : }
: : else if (Nums[i] == -1)
: : DisplayMainMenu();
: : }
: : return Nums[MAX_NBR_INTEGERS];
: : }
: :
: :
: : void DisplayStatistics (void)
: : {
: : int
: : Nums[MAX_NBR_INTEGERS];
: : cout << "Sorting Integers\n"
: : << "\n================"
: : << "\nThe unsorted integers:\n" ;
: :
: :
: :
: :
: : }
: :
: :
: :
: : void Pause (void)
: : {
: : cout<<"\n\n\n\n Press enter to continue...";
: : char
: : ch = '\0';
: : cin.get(ch);
: : while ((ch != '\n')&&(ch != '\r'))
: : cin.get(ch);
: : }
: :
: :
: :
|