2017-02-15 7 views
1

내 C++ 클래스에서는이 코드에 다른 측면을 계속 작성해야합니다. 현재 2 개의 오류가 발생하고 내가 뭘 잘못하고 있는지 알지 못하는 곳에 갇혀 있습니다. 이 프로그램은 이름과 개인 정수를위한 개인용 자동차 또는 문자열을 3, 5 및 둘 모두로 게임 검사에 입력하도록합니다. 3 & 5. 클래스 내에서 get 함수와 put 함수를 사용합니다. 입력 값을 출력합니다. 필자는 본질적으로 프로그램을 알아 냈지만 컴파일되지는 않을 것이며 그 이유는 확실하지 않습니다. 여기 내 코드입니다 :클래스, private, public, 생성자, 함수, 정수 및 문자열을 사용하여 학습 추가 학습

#include <iostream> 
#include <iomanip> 
using namespace std; 
using std::istream; 

// declare the max size the username input can be 
const int MAX = 14; 

enum FIZZBUZZ { ABORT = 0, FIZZBUZZ, FIZZ, BUZZ }; 


class CFizzbuzz        // Class definition at global scope 
{ 
    // make sure our constructor, destructor, plus member functions are 
    // all public and available from outside of the class. 
public: 

    CFizzbuzz() {}    // Default constructor definition 
    ~CFizzbuzz() {}    // Default destructor definition 


           // function members that are public 

           // get the user's name and their value from the console and 
           // store those results into the member variables. 
    void getFizzbuzz() 
    { 
     cout << "Please enter your name: " << endl; 
     cin >> m_myName; 

     cout << "Please enter your number for the FizzBuzz game: " << endl; 
     cin >> m_myNum; 
    } 

    // return the user's number type entered 
    int putFizzBuzz() 
    { 
     return m_myNum; 
    } 

    char* getName() 
    { 
     return m_myName; 
    } 

    // logic to check to see if the user's number is 0, fizz, buzz, or  fizzbuz 
    int getRecord(int num) 
    { 
     if (num == 0) 
     { 
      return ABORT; 
     } 
     else if (num % 5 == 0 && num % 3 == 0) // fizzbuzz number 
     { 
      return FIZZBUZZ; 
     } 
     else if (num % 5 == 0) // buzz number 
     { 
      return BUZZ; 
     } 
     else if (num % 3 == 0) // fizz number 
     { 
      return FIZZ; 
     } 
     else 
      return num; 
    } 

    // private data members only available inside the class 
private: 
    int  m_myNum; 
    char m_myName[MAX]; 
}; 


int main() 
{ 
    CFizzbuzz myClass; 


    cout << "Welcome to my Fizzbuzz game, you are to guess the location of a " 
     << "number which if is divisible by 5 and 3 you will win with " 
     << "the output of Fizzbuzz. " << endl; 
    cout << "Please enter an integer value between 0 and 3 " 
     << "representing the row location of the number for the game, " 
     << "then press the Enter key: " << endl; 

    for (;;) 
    { 
     myClass.getFizzbuzz(); 

     int num = myClass.putFizzBuzz(); 
     switch (myClass.getRecord(num)) 
     { 
     case ABORT: 
      cout << myClass.getName() << "\nThank you for playing\n"; 
      system("PAUSE"); 
      return 0; // exit program 

     case FIZZ: 
      cout << "Sorry, " << myClass.getName() << ", number is a Fizz, please try again.\n"; 
      break; 

     case BUZZ: 
      cout << "Sorry, " << myClass.getName() << ", number is a Buzz, please try again.\n"; 
      break; 

     case FIZZBUZZ: 
      cout << "You win you got FizzBuzz!!!" << endl; 
      break; 

     default: 
      cout << "Sorry, " << myClass.getName() << ", number is a not a Fizz, Buzz, or Fizzbuzz\nPlease try again.\n"; 
      break; 
     } 
    } 
} 

이 내가지고있어 오류가 있습니다 :

LNK2019, 당신이 의견에 언급 된 오류 (Unresolved external symbol [email protected]) 나는 당신이를 만든 말하고 싶지만 바탕으로 LNK1120

+0

더 구체적인 오류를 제공해 줄 수 있습니까? _LNK2019_ 및 _LNK1120_ –

+0

대신 오류를 설명하는 줄을 제공하십시오. 또한 9 개의 오류가 발생했다고합니다. 그렇다면 다른 7 가지 오류는 무엇입니까? –

+0

두 가지 오류 만 있습니다. 나는 이전에 9 명을 가지고 있었다. 읽은 오류 : 확인되지 않은 외부 기호 _WinMain @ 16 "int_cdecl invoke_main (void)"(? invoke_main @@ YAHXZ) – phoenixCoder

답변

0

Visual Studio에서 Win32 프로젝트 (GUI 프로젝트)를 사용하지만 코드는 콘솔 응용 프로그램을위한 것입니다.

프로젝트를 다시 만들거나 Windows에서 프로젝트 설정으로 콘솔을 변경하여 Win32 응용 프로그램에서 콘솔 응용 프로그램으로 프로젝트 유형을 변경해야합니다. 후자에 대한 자세한 내용은 다음 링크를 참조하십시오 :

https://msdn.microsoft.com/en-us/library/fcc1zstk.aspx

+0

고쳐. 그러나 끝내기를 원하는 것처럼 보이지 않으며 반복해서 계속해서 플레이합니다. – phoenixCoder

0

내가 다른 반환 NUM 의심 될 것이다. 1 또는 2를 입력하면 어떻게됩니까? 분명히 계수는 fizz 또는 잡음을 제공하지 않지만 enum 값에 따라 getRecord() 함수는이를 반환합니다. NONE enum 값을 -1로 설정하면 fizz 또는 buzz이 아님을 나타냅니다.

enum 값에 대해 기억해야 할 점은 컴파일 할 때 실제 숫자로 해석된다는 것입니다. 따라서 1을 입력하고 모듈러스가 fizz, buzz 또는 fizzbuzz를 표시하지 않고 1을 반환하면 switch case 문이 fizzbuzz로 해석됩니다 (의도 한 말장난).

예상대로 작동하지 않는다는 의견을 제시하는 한 자세한 내용을 입력하십시오.