I can't figure it out.

#include <iostream>
#include "GameMenu.h"
#include "PlayerInfo.h"

using namespace std;

GameMenu::GameMenu() {

}

void GameMenu::display() {
	cout << "-----------------------------------------------------------------" << endl;
	cout << "Welcome to \"Hot or Cold\"" << endl;
	cout << "-----------------------------------------------------------------" << endl;
	cout << "OBJECTIVE:\t\tGuess the number in fewest number of guesses." << endl;
	cout << "SCORING:\tThe fewer your guesses, the greater your score." << endl;
	cout << "MAX SCORE:\t200 points." << endl;
	cout << "\t\tYou start with a free 10 points :D\n\n" << endl;

	PlayerInfo pi;
	pi.setupPlayerInfo();
}

void GameMenu::terminateGame() {
	
}
#include <iostream>
#include "PlayerInfo.h"
#include "FileController.h"

;using namespace std;

void setupPlayerInfo() {
	string userName;
	cout << "\nPlease provide your name. (Names are case sensitive)." << endl;
	getline(cin, userName);
	cout << "\nYou input '" << userName << "'. Continue using this name?" << endl;
	cout << "1 - Yes" << endl;
	cout << "2 - No " << endl;

	int choice;
	cin.clear();
	cin >> choice;
	switch(choice) {
		case 1:
			system("cls");
			{
				bool userExists = false;
				FileController fc;
				string tmp;
				while (!fc.getInFile().eof()) {
					fc.getInFile() >> tmp;
					if (tmp == userName) {
						cout << "Welcome back "<< userName << "!\n\n" << endl;
						userExists = true;
						fc.getInFile().close();
						break;
					}
				}
				if (!userExists) {
					cout << "Great! Let's begin!\n\n" << endl;
				}
			}
			break;
		case 2:
			setupPlayerInfo();
			break;
		default:
			cout << "\nInvalid Input." << endl;
			setupPlayerInfo();
			break;
	}
}

PlayerInfo::PlayerInfo() {

}

void PlayerInfo::setPlayerName(string name) {
	playerName = name;
}

string PlayerInfo::getPlayerName() {
	return playerName;
}

You'll notice that I have a ';' before the namespace declaration. I don't know why but my code won't run if it's not there. It gives me a "error C2143: syntax error : missing ';' before 'using'" error -.-

Also, why won't it let me call the setPlayerName function within PlayerInfo?

Sorry for the newbie questions, I just started a class using C++...

You've probably omitted a semicolon after one of your class declarations in the header file. See if that fixes both errors, otherwise you can post back with your new error message. What does setupPlayerInfo belong with?

Also lines 40 and 44 set up recursive calls to the function. This is not the best approach. Wrap your data entry portion in a do while loop.

There are other minor issues like with .eof() but let's get the heart of the problem figured out.

What exactly is the LNK2019 error saying?

You've probably omitted a semicolon after one of your class declarations in the header file. See if that fixes both errors, otherwise you can post back with your new error message. What does setupPlayerInfo belong with?

Also lines 40 and 44 set up recursive calls to the function. This is not the best approach. Wrap your data entry portion in a do while loop.

There are other minor issues like with .eof() but let's get the heart of the problem figured out.

AHA! I was missing a semicolon on a header file. Darn JAVA programming ;P

I don't quite understand what you mean by "What does setupPlayerInfo belong with". You mean what class? It is part of PlayerInfo.h/PlayerInfo.cpp

I really appreciate your help :) I'd like to develop good programming practices from the start to avoid developing bad habits.

I'll look into coding the do-while loop. Would it look something like this?:

do {
// code here
cin.clear(); // needed for clearing the input to avoid an infinite loop?
} while (choice != 1)

What exactly is the LNK2019 error saying?

1>------ Build started: Project: HotOrColdGame, Configuration: Debug Win32 ------
1> Scoring.cpp
1>GameMenu.obj : error LNK2019: unresolved external symbol "public: void __thiscall PlayerInfo::setupPlayerInfo(void)" (?setupPlayerInfo@PlayerInfo@@QAEXXZ) referenced in function "public: void __thiscall GameMenu::display(void)" (?display@GameMenu@@QAEXXZ)
1>E:\HotOrColdGame\Debug\HotOrColdGame.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

AHA! I was missing a semicolon on a header file. Darn JAVA programming ;P

I don't quite understand what you mean by "What does setupPlayerInfo belong with". You mean what class? It is part of PlayerInfo.h/PlayerInfo.cpp

It didn't have a PlayerInfo:: in front of it, that's all.

I'll look into coding the do-while loop. Would it look something like this?:

Do (setupPlayerInfo()) {
// code here
cin.clear(); // needed for clearing the input to avoid an infinite loop?
} while (choice != 1)

It'd be within setupPlayerInfo, actually. cin.clear() is used when you've taken in bad input in the sense of looking to read into an integer and someone types characters. Wrap the loop around lines 9 through 46 and at the end of case one, set a flag to exit the loop.

bool breakflag = false;
do{
   //get input here
   if (choice == 1)
   {
      //all the stuff from case 1
      break;
    }
}while(true); //loop until break is hit

There will be some more rearranging necessary but that's the gist of it.

The reason you had an error saying "missing ; before using" is because you were missing the ; in you other file and so it was telling you that somewhere before using you should have a ;. Try taking it out of your code now and see if it complains.

It didn't have a PlayerInfo:: in front of it, that's all.

It'd be within setupPlayerInfo, actually. cin.clear() is used when you've taken in bad input in the sense of looking to read into an integer and someone types characters. Wrap the loop around lines 9 through 46 and at the end of case one, set a flag to exit the loop.

bool breakflag = false;
do{
   //get input here
   if (choice == 1)
   {
      //all the stuff from case 1
      break;
    }
}while(true); //loop until break is hit

There will be some more rearranging necessary but that's the gist of it.

LOL Another newbie moment -.- Thanks for seeing that I forgot the PlayerInfo:: piece. I think that solved it. Also, here's my do-while loop:

int choice;
do {
	cin >> choice;
	system("cls");
	if (choice == 1) {
		bool userExists = false;
		FileController fc;
		string tmp;
		while (!fc.getInFile().eof()) {
			fc.getInFile() >> tmp;
			if (tmp == userName) {
				cout << "Welcome back "<< userName << "!\n\n" << endl;
				userExists = true;
				fc.getInFile().close();
				break;
			}
		}
		if (!userExists) {
			cout << "Great! Let's begin!\n\n" << endl;
		}
	}
	break;
} while (true);

What is the advantage of using the do-while loop? Wouldn't the screen just keep outputting whatever the user typed in until it met the criteria necessary? Wouldn't that look odd?

What do I use instead of cin.clear() to clear out the buffer? It holds onto the last user input.

Move the break on 22 up into the if statement otherwise it will break regardless of good input or not.

Put in a cin.ignore() before the cin if it's holding onto the newline character. Here's a good reference on cin.clear() so you can see under the hood a bit (http://www.cplusplus.com/reference/iostream/ios/clear/).

Move the break on 22 up into the if statement otherwise it will break regardless of good input or not.

Put in a cin.ignore() before the cin if it's holding onto the newline character. Here's a good reference on cin.clear() so you can see under the hood a bit (http://www.cplusplus.com/reference/iostream/ios/clear/).

I see.

I don't know where to put that break you mentioned without it causing any of the loops to exit prematurely. I also think I'm running into that eof problem you stated early because it seems to never reach the end of the file... (I found this but it doesn't seem to be working correctly. It gets stuck in an infinite loop.)

And I don't know if the do-while is working for what I need unless I'm really missing something. For example, If a user mistypes there name and the user chooses "2 - No" for the name confirmation, the program gets stuck taking empty data and doesn't do anything with it.

You have your break on line 22. Regardless of what happens with the choices you will always break out of the loop. So if the user chooses 1 or 2 you'll hit the break and exit out of the (outer) while loop.

My interpretation of what you are trying to do is that if the user selects 2 the loop will cycle back for more input. Therefore, if you move the break on 22 between lines 20 and 21, the code will then break out of the (outer) while loop (after lines 6-19 has taken place) and your function will return.

I think I might have been ambiguous in saying break before, I don't mean the inner while used to read in the file. For that one you can move what's in line 10 (minus the ; ) right into the loop condition instead of the .eof() call.

This is the word on .eof http://www.daniweb.com/forums/post155265-18.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.