Error checking C++ function - help - more explanation can be added if needed

I need help with a c++ error function code.

Notes on input data
 In the number of bedrooms column
A value other than 1 or 2 generates an error
 In the Type column
A code other than S, R or D for 1 bedroom generates an error
A code other than R or D for 2 bedrooms generates an error
 In the Bath column, any code other than X or a blank generates an error
 In the Office column
Any code other than a blank for a one bedroom apartment generates an error
any code other than O or a blank for a two bedroom apartment generates an error
 In the Floor column, any number is acceptable so no error checking is necessary, it will be an integer
 If an error is generated, no fees should be calculated and fees should be shown with xxx.xx in the fee column in the output file
 In the garage column, any code other than Y or y does NOT generate an error, the garage cost is just set to 0.00



Here's a little background on the problem :
Explanation of Input
Stephanie Fitzgerald 2 D X O 4 Y
Name - Stephanie Fitzgerald - The first 20 characters are the name
Number of bedrooms - 2 An integer
Apartment Type - D - 2 characters, a blank and D
Features - X 2 characters, a blank and X
Office - O 2 characters, a blank and O
Floor- An integer 4
Garage- 2 characters, a blank and Y

Here is the first line of input.

Stephanie Fitzgerald 2 D X O 4 Y

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//--------------------------------------------------------
//Function 4 - DetermineErrorCode
//Determine the error code based on the codes and number of bedrooms
//--------------------------------------------------------
bool DetermineErrorCode(char& apartmentType, char& bathFeatureType, char& officeAddition,
	int& numberOfBedrooms)
{
	bool errorCodeFlag;

	errorCodeFlag = false;

	if (bathFeatureType != 'X' || ' ')
	{
		errorCodeFlag = true;
	}
	if (errorCodeFlag = false && numberOfBedrooms != 1 || 2)
	{
		errorCodeFlag = true;
	}

	return errorCodeFlag;
}


There is more to this testing, yet I have not yet completed it. I had it done ( I thought) until my classmates began posting different grand totals for the rent, based on 27 lines of input of these types of codes. there are some that produce errors, and others that just add up the grand total. I can attach a PDF of the instructions of this entire lab if you need it, or I have not explained it well enough.

Starting at apartment type, all variables are saved into a char array of 6+1 to end the null terminator, ending at floornumber.. Here is a sample of the input.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Input First Renter's name from input file - used as the primer for EOF loop
	fin.get(renterName, NAME_LENGTH+1);

	//While there is data in the file, execute the code below.
	while (!fin.eof())
	{
		//Input number of bedrooms from the current line in the input file
		fin >> numberOfBedrooms;

		//Inputs the next 3 codes on the line into a char array
		fin.get(rentCodes, RENTER_CODE_LENGTH + 1);

		//Input floor number and garage option codes from input file 
		fin >> floorNumber;
		fin >> garageOption;


This is for a college class, and i've spent probably about 15 hours solely on this particular project. I can post the entire project and instructions if needed. It's due in about 72 hours. I am having a real fuck of a time getting it to work, and I need help on just the error checking portion - I can't get any of the results my peers get in the class - which only about 4 have posted about finishing, out of 30~.
Last edited on
Too much background text. Here are some problems I see with the code posted.

numberOfBedrooms != 1 || 2)

This wont work, here is how you test for multiple conditions (Same for other if statement). It also seems like you want && here not ||.

numberOfBedrooms != 1 && numberOfBedrooms != 2)

if (errorCodeFlag = false
= is used for assignment, == is used to check a variable. You want ==.

It isn't a good idea to use eof() for checking the end of a file. Put the fin.get in the while loop.
http://stackoverflow.com/questions/5605125/why-is-iostreameof-inside-a-loop-condition-considered-wrong

Not sure why you are passing the parameters to DetermineErrorCode by reference in this case, it wont be faster for int/char. Not a huge deal though.
Topic archived. No new replies allowed.