2017-02-15 57 views
1

在我的C++类中,我们的任务是在这个代码中构建不同的方面。我目前收到2个错误,并且卡在我不知道自己做错了什么的地方。该程序需要一个私人汽车或字符串的名称和一个私人整数输入游戏检查可分性3,5,和两个3 & 5.我要在课堂上使用get函数和put函数输入值并输出它们。我基本上已经想出了该程序,但它不会编译,我真的不确定为什么。这里是我的代码:使用类,私有,公共,构造函数,函数,整数和字符串进一步学习的程序

#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,LNK1120

+0

你能提供更具体的错误吗?请提供描述您的错误的行,而不是_LNK2019_和_LNK1120_ –

+0

另外您还说您收到9个错误。如果是这样的话,那么你的其他7个错误是什么? –

+0

只有两个错误。我以前有过9次。错误读取:无法解析的外部符号_WinMain @ 16在函数“int_cdecl invoke_main(void)”(?invoke_main @@ YAHXZ)中引用 – phoenixCoder

回答

0

根据您在评论中提到的错误(Unresolved external symbol [email protected])我会说,你创建了一个Win32项目(一个GUI项目)在Visual Studio中,但您的代码旨在成为控制台应用程序。

您需要将项目的类型从Win32应用程序更改为控制台应用程序,方法是重新创建它,或者在项目设置中将子系统从Windows更改为控制台。参见后者以下链接了解更多信息:

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

+0

修复它。它似乎并不想结束,而是一直在玩 – phoenixCoder

0

我将可疑否则返回NUM的。当你输入1或2时会发生什么?显然,模数并不提供嘶嘶声或嗡嗡声,但是根据你的枚举值,函数getRecord()返回它的值。我将有一个无枚举值设置为-1,以表明它既不是一个嘶嘶声或嗡嗡声。

要记住一个枚举值的事情是它编译时解析为一个实际的数字。所以,当你输入1,并且模数不能证明是一个嘶嘶声,嗡嗡声,或者一个混乱的声音,并且你返回1时,即使情况并非如此(双关意图),开关盒语句也会解决。

只要您评论说它不能按预期工作,请输入更多详细信息。

相关问题