나는 a, q, h 등이 선언 된 변수가 아니라는 오류가 나오고 있지만이를 수정하는 방법을 모르겠습니다. 다음은 내 코드 예제입니다.메뉴 중첩 된 루프 (기본 C++)
while 루프 내에서 userinp를 인식하지 못하는 오류가 발생하지만 전역 변수를 선언하지 않고 while 루프 외부에서 변수 저장 영역을 전송하는 방법을 모르겠습니다. , 나는 피하고 싶다.
마지막 질문 : 모든 키를 즉시 각 메뉴 항목 다음에 주 메뉴로 되돌리려면 원하는 항목을 선택해야합니다.
도움을 주시면 대단히 감사하겠습니다.
while(userinp != 'q') {
을 그리고이 :
//Runs a program with a menu that the user can navigate through different options with via text input
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <ctype.h>
#include <string>
using namespace std;
int main()
{
int userinp;
cout<<"Here is the menu:" << endl;
cout<<"Help(H) addIntegers(A) subDoubles(D) Quit(Q)";
cin >> userinp;
userinp = tolower(userinp);
while userinp != q //loop while no q is input
{
if userinp == h
{
cout <<"This is the help menu. Upon returning to the main menu, input A or a to add 2 intergers." << endl;
cout <<"Input D or d to subtract 2 doubles. Input Q or q to quit.";
}
if userinp == a
{
int a, b, result;
cout <<"Enter two integers:";
cin << a << b;
result = a + b;
cout << "The sum of " << a << " + " << b << " = " << result;
}
}
}
'CIN << << B되어야하는 경우에 대해 U 정수 2) 상태 선언;'되어야 cin >> a >> b;'. 당신은 불필요한 헤더 파일'iomanip','algorithm'과'string'을 포함하고 있습니다. 그리고'ctype.h'는 C++ 특정 헤더를 고수하기 위해'cctype'이어야합니다. – jodag
위의 변경 사항을 사용하고 일부 코드를 추가했지만 디버거/빌드에서이 코드를 얻었습니다. http://pastebin.com/RNtECZVJ – Sean
@Sean 링크를 수정하십시오. 또는 새 질문을 원래 질문으로 수정하거나 충분히 다를 경우 새로운 질문을 올리십시오. – nhgrif