1

In my c++ class, we have been tasked to keep building different aspects into this code. I am currently getting 2 errors and am stuck where I don't know what I am doing wrong. The program takes a private car or string for a name and a private integer to be input into the game checking for divisibility by 3, 5, and both 3 & 5. I am to use a get function and a put function within the class taking the input values and outputting them. I have essentially figured out the program but it will not compile and I am really unsure why. Here is my code:

#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;
        }
    }
}

These are errors I'm getting:

LNK2019, LNK1120

2 Answers2

0

Based on the errors you mentioned in comments (Unresolved external symbol _WinMain@16) I'd say that you created a Win32 project (a GUI project) in Visual Studio but your code is meant to be a console application.

You need to change the type of your project from Win32 application to Console application by either re-recreating it or changing the Subsystem from Windows to Console in project settings. See the following link for more information on the latter:

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

iosdude
  • 1,131
  • 10
  • 27
0

I would be suspicious of the else return num. What happens when you enter 1 or 2? Clearly the modulus doesn't provide a fizz or buzz but based on your enum values the function getRecord() returns that it does. I would have a NONE enum value set to -1 to indicate that it is neither a fizz or buzz.

The thing to remember about an enum value is that it resolves to an actual number when compiled. So when you input 1, and the modulus doesn't prove a fizz, buzz, or a fizzbuzz AND you return 1, the switch case statement will resolve to fizzbuzz even though this is not the case (pun intended).

As far as you commenting that it's not working as expected, please input more details.

Clay Brooks
  • 182
  • 1
  • 11