GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Oct-2009, 00:33
jnCPP jnCPP is offline
New Member
 
Join Date: Oct 2009
Posts: 9
jnCPP will become famous soon enough

string and reference confusion


Below is my semi-finished program..
I have a couple of issues that have me stuck, and after looking up several different ways to solve them, I'm still stuck.
- The reference I'm using for &nameLoc doesn't seem to be passing,
because the output for Byfuglien is always from the 0 element.
I'm not sure how to properly increment a search in the playerSearch function at the very end.

- When I try to input a different name that doesn't exist within the
players[], the program loops infinitely and my compiler essentially crashes.

I would definitely appreciate any insight to what I could change,
and what I'm doing wrong. (Preferably not a direct solution,
just a push in the right direction.)

Thanks in advance.


CPP / C++ / C Code:
#include <iostream>
#include <iomanip>
#include <fstream>


#define NUM_PLAY 30

using namespace std;

//  Declaration of the 3 different arrays

int buildArrays(int goals[], int assists[], int shots[]);
void sortArrays(string players[], int goals[], int assists[], int shots[], int numPlayers);
void printArrays(string players[], int goals[], int assists[], int shots[], int numPlayers);
bool playerSearch(string players[], int numPlayers, string nameToFind, int &nameLoc);

int main()
{

int assists[NUM_PLAY], //  Declarations for the 3 different arrays to be built
    goals[NUM_PLAY],
    shots[NUM_PLAY];
int numPlayers,		   //  Declaration for the return value of the build array
	nameLoc,
	whereName;
bool result;

string nameToFind;
// Declares and initializes the string players array
string players[NUM_PLAY] = { "Martin Havlat", "Patrick Kane", "Jonathan Toews",
                             "Kris Versteeg", "Brian Campbell", "Andrew Ladd",
                             "Dave Bolland", "Patrick Sharp", "Duncan Keith",
                             "Cam Barker", "Dustin Byfuglien", "Brent Seabrook",
                             "Troy Brouwer", "Sammy Pahlsson", "Colin Fraser",
                             "Ben Eager", "Matt Walker", "Adam Burish",
                             "Aaron Johnson", "Niklas Hjalmarsson", "Brent Sopel",
                             "Jack Skille", "Jordan Hendry", "Pascal Pelletier",
                             "Tim Brent", "Jacob Dowell" };
	


numPlayers = buildArrays(goals, assists, shots);            //  calls the function to build the arrays from the players.txt file

sortArrays(players, goals, assists, shots, numPlayers);    //   calls the function to sort the built arrays

printArrays(players, goals, assists, shots, numPlayers);   //   calls the function to print the sorted arrays


nameToFind = "Dustin Byfuglien";
result = playerSearch(players, numPlayers, nameToFind, whereName);

	if (result == true)
	{
	cout << nameToFind << " scored " << goals[whereName] << " goals and had " << assists[whereName] << " assists." << endl;
	}
	else 
	{
	cout << nameToFind << " was not found." << endl;
	}


return 0;
}


/***************************************************************
Function: buildArrays

Use:      Reads information from players.txt and sorts it into
          3 different arrays.

Arguments: three Arrays, each will be filled with information
           from the .txt file

Returns:  the value of i, which is the number of elements that
          were initialized during the building of the arrays

Notes:    includes a loop that opens the file, and returns a
          message of error if the file didn't open properly
***************************************************************/



int buildArrays(int goals[], int assists[], int shots[])
{

int num,  // declares num for use as variable to assign
          // a value for each element in the array
    
	i=0;  // declares i for use as the counter of how many
	      // elements have been initialized and assigned

//  declares a stream to read from players.txt	  
ifstream inFile;

//  opens the file and runs a loop to check if the file
//  was opened correctly
inFile.open ("players.txt");
if (inFile.fail () )
	{
	cout << "input file did not open.";
	exit(0);
	}

//  Loop to build the arrays
	inFile >> num;
	while(inFile)
		{
		goals[i] = num;
		inFile >> num;
		assists[i] = num;
		inFile >> num;
		shots[i] = num;
		i++;
		inFile >> num;
		}
inFile.close ();

return i;  // Value is the number of elements assigned to an array
}

/***************************************************************
Function: calcTriArea

Use:      sorts the arrays that were built from the buildArrays
          function by ascending order alphabetically by player
		  name.

Arguments: four arrays, one is a string, the other three are
           int arrays, and the int numPlayers which is the
		   amount of elements that were initialized during
		   the build function

Returns:  nothing

Notes:    This function also swaps each array according to each
          swap that occurs with the player name array.
***************************************************************/


void sortArrays(string players[], int goals[], int assists[], int shots[], int numPlayers)
{
int top = 0,				// Declares top to be used as the first
    last = numPlayers,      // Declares last to be used as the last element
	ssf,                    // Declares ssf to be used as the smallest element
	ptr,                    // Declares ptr as the number of elements
	temp,					// Declares temp, temp1, temp2, for swapping
	temp1,
	temp2;
string swap;				// Declares swap as the variable for swapping

//  Loops for the selection sort algorithm	  
do
{
ptr = top;
ssf = top;
	do 
	{
	  if (players[ptr] < players[ssf])
	  {
	  ssf = ptr;
	  }
  	  ptr = ptr + 1;
	}
	while (ptr < last);

//  4 different swaps for every time a player name is swapped
//  the corresponding element in the arrays is swapped	  
swap = players[top];
players[top] = players[ssf];
players[ssf] = swap;

temp = goals[top];
goals[top] = goals[ssf];
goals[ssf] = temp;

temp1 = shots[top];
shots[top] = shots[ssf];
shots[ssf] = temp1;

temp2 = assists[top];
assists[top] = assists[ssf];
assists[ssf] = temp2;

top = top + 1;
}
while (top < last);
}

/***************************************************************
Function: printArrays

Use:      Displays a heading, and each of the categories from
          the information of buildArrays.

Arguments: 4 arrays, players, goals, assists, shots, and an int
           numPlayers

Returns:  nothing

Notes:    This function also calculates the points and shot %
***************************************************************/

void printArrays(string players[], int goals[], int assists[], int shots[], int numPlayers)
{
int d,				//  Declares d as the variable used for counting
    numPoints,      //  declares the variable for number of points
    numAssists;     //  Declares the variable for number of assists
double shotPercent, //  Declares the variable for shot percent
	   numGoals,    //  Declares the variable for number of goals
	   numShots;    //  Declares the variable for number of shots

//  Heading of information before the information is displayed
cout << endl << endl;
cout << "             Chicago Blackhawks 2008-2009 Player Stats" << endl << endl << endl;
cout << "Players		        Goals   Assists	 Points  Shots  Shooting %" << endl;

cout << "--------------------------------------------------------------------" << endl;

//  Loop to display the stats for each player, as well as calculate
//  the number of points and shot percent of each player.
for (d = 0; d < numPlayers; d++)
{
numGoals = goals[d];
numAssists = assists[d];
numShots = shots[d];
numPoints = numGoals + numAssists;

// condition that if number of shots = 0
// shooting percent is also 0
if (shots[d] != 0)
shotPercent = numGoals/numShots * 100;
else 
shotPercent = 0;

//  Code to display each player information
cout << left << setw(20) << players[d];
cout << right << setw(8) << goals[d];
cout << right << setw(8) << assists[d];
cout << right << setw(8) << numPoints;
cout << right << setw(8) << shots[d];
cout << setiosflags(ios::fixed | ios::showpoint) << setw(9) << setprecision(1) << shotPercent << endl;

}
}

/***************************************************************
Function: playerSearch

Use:      checks to see if the name is within the array of
		  player names.

Arguments: array of player names, number of players,
           string of name to find, and reference for location of
		   name

Returns:  true if the name was found, and false if not


***************************************************************/

bool playerSearch( string players[], int numPlayers, string nameToFind, int &nameLoc)
{
int j = 0;
bool res;

	while (j < numPlayers)
	{
	if (nameToFind == players[j])
	{
	res = true;
	break;
	}
	else 
	{
	res = false;
	j++;
	}
	}
if (res = true)
{
return true;
}
else 
{
return false;
}
}
  #2  
Old 28-Oct-2009, 05:29
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: string and reference confusion


I've got an idea...how about giving us only part of the problem and seeing if we can come up with our own "players.txt" input file from your code...you know, just as an exercise to see how good we are and how much time we have available to help you solve your problems?

I'm wondering why your "coding style" has the following:

CPP / C++ / C Code:
    inFile.open ("players.txt");
    if(inFile.fail ())
    {
        cout << "input file did not open.";
        exit(0);
    }

...you put a space between the function names and the parens in some cases, then in some other cases you don't...such as "exit(0)" and "setw(...)" and "setiosflags(...)" and some of your own functions such as buildArrays, sortArrays and printArrays?

You may want to decide on one or another style and be consistent throughout all of your code.

While you're always "free" to create your own style, using an existing, "standard" style is probably a better choice while you're learning. A typical convention is to not use a space between the function name and the parenthesis but to use a space between the parenthesis of NON functions such as in the case of conditionals:

CPP / C++ / C Code:
exit(0);
executeFunctionCall(someArgs);
while (someCondition == true) { ... }
for ( int i = 0; i < NINETY_BILLION; i++) { ... }
if (i < INT_MAX) { ... }


Additionally, I'd recommend that you treat every conditional statement as a "multiline" conditional. That is, use "{" and "}" for every single if, for, while, etc. It is a good habit to get into.

I'd probably recommend that you avoid global data as much as possible...at least for now. When you better understand its virtues and vices, then you will be ready to selectively apply it.

So, if you want to send us at least a portion of the players.txt content, we may have the energy to revisit this problem. Of course, anyone else is welcomed to solve it without it.

Lastly, you say that "my compiler crashes." I find that extremely difficult to believe. Perhaps you mean that your IDE crashes? One of the biggest issues programmers have to encounter is being specific. That means "exacting." The "computer" will do exactly what you program it to do within the context of its operating environment. My guess is that you executed the compiler LONG (really, really long in terms of processor cycles) before you actually executed your code and that the compiler execution terminated successfully long before the linker was invoked and successfully terminated and long before you could even move the mouse (or press hotkeys) to begin execution of your program.

While it is not a "sin" to use "compiler" as a synonym for your toolchain (a collection of tools that enable you to easily build, debug and execute programs), it may be useful for you to begin using the most accurate explanations of what happens as early in your career as possible...even if the "extent" of your career is only a semester long C++ course. By indicating exactly what happened, you also earn the confidence of other programmers.



MxB
  #3  
Old 28-Oct-2009, 06:09
jnCPP jnCPP is offline
New Member
 
Join Date: Oct 2009
Posts: 9
jnCPP will become famous soon enough

Re: string and reference confusion


My apologies, for the mistakes I make in your eyes don't seem to be mistakes from my perspective just yet.
In regards to the code that opens the file and outputs an error if it didn't open, it's something required for the program. As for the formatting of my code, I didn't even realize that I had been inconsistent, but thank you for pointing that out, it will be something that I keep in mind from now on.


The players.txt file is the following group of numbers -- the first column is the number for goals, followed by assists and finally shots.
Code:
29 48 249 25 45 254 34 35 195 22 31 139 7 45 108 15 34 195 19 28 111 26 18 184 8 36 173 6 34 101 15 16 202 8 18 132 10 16 126 7 11 88 6 11 67 11 4 80 1 13 83 6 3 83 3 5 27 1 2 15 1 1 15 1 0 14 0 0 1 0 0 7 0 0 0 0 0 0

I personally didn't feel that this would be entirely relevant to the assistance for which I was asking.. Though, now in retrospect I realize that if you were to offer any assistance, you would need the file to utilize the code I wrote.. otherwise it's like trying to drive blindfolded.

- To be a bit more specific, my compiler doesn't crash. I also didn't realize this would cause confusion. Essentially, when I compile and build the program, there are no errors. When I execute the program, however, the result is as if I had coded an infinite loop, and after about 3-4 seconds, I get a message from windows notifying me that quincy2005 has stopped working.
This happens if I change "Dustin Byfuglien" to my own name, or any name that isn't initialized as an element into the players[] array.

-- I don't mean to sound too defensive, and I greatly appreciate your criticism and advice. I'll never learn if I don't make mistakes, so thanks for your patience in looking over my code, and thanks in advance if you happen to look over it again.

-Justin
  #4  
Old 28-Oct-2009, 06:37
jnCPP jnCPP is offline
New Member
 
Join Date: Oct 2009
Posts: 9
jnCPP will become famous soon enough

Re: string and reference confusion


After looking over my code again in an attempt to understand what I was doing wrong, I figured it out.
- My first mistake was not assigning a value to nameLoc to be 'passed back' to int main().
- My second mistake was in the same function, where I had typed
CPP / C++ / C Code:
if ( res = true )
but I changed it to
CPP / C++ / C Code:
 if ( res == true ) 

and now it's working just fine.
  #5  
Old 28-Oct-2009, 06:51
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: string and reference confusion


Quote:
Originally Posted by jnCPP
After looking over my code again in an attempt to understand what I was doing wrong, I figured it out.
- My first mistake was not assigning a value to nameLoc to be 'passed back' to int main().
- My second mistake was in the same function, where I had typed
CPP / C++ / C Code:
if ( res = true )
but I changed it to
CPP / C++ / C Code:
 if ( res == true ) 

and now it's working just fine.


You may want to take a look at the following resource:

Gimpel On-Line Demos

Gimpel has an online version of their tools available that evaluates C and C++ code (separate links per language) and, as shown below, finds these same errors that you found.

Output:

Code:
FlexeLint for C/C++ (Unix) Vers. 9.00c, Copyright Gimpel Software 1985-2009 --- Module: diy.cpp (C++) 1 #include <iostream> 2 #include <iomanip> 3 #include <fstream> 4 5 6 #define NUM_PLAY 30 7 8 using namespace std; 9 10 // Declaration of the 3 different arrays 11 12 int buildArrays(int goals[], int assists[], int shots[]); 13 void sortArrays(string players[], int goals[], int assists[], int shots[], int numPlayers); 14 void printArrays(string players[], int goals[], int assists[], int shots[], int numPlayers); 15 bool playerSearch(string players[], int numPlayers, string nameToFind, int &nameLoc); 16 17 int main() 18 { 19 20 int assists[NUM_PLAY], // Declarations for the 3 different arrays to be built 21 goals[NUM_PLAY], 22 shots[NUM_PLAY]; 23 int numPlayers, // Declaration for the return value of the build array 24 nameLoc, 25 whereName; 26 bool result; 27 28 string nameToFind; 29 // Declares and initializes the string players array 30 string players[NUM_PLAY] = { "Martin Havlat", "Patrick Kane", "Jonathan Toews", 31 "Kris Versteeg", "Brian Campbell", "Andrew Ladd", 32 "Dave Bolland", "Patrick Sharp", "Duncan Keith", 33 "Cam Barker", "Dustin Byfuglien", "Brent Seabrook", 34 "Troy Brouwer", "Sammy Pahlsson", "Colin Fraser", 35 "Ben Eager", "Matt Walker", "Adam Burish", 36 "Aaron Johnson", "Niklas Hjalmarsson", "Brent Sopel", 37 "Jack Skille", "Jordan Hendry", "Pascal Pelletier", _ 38 "Tim Brent", "Jacob Dowell" }; diy.cpp 38 Info 785: Too few initializers for aggregate 'players' of type 'std::basic_string<char> [30]' 39 40 41 42 numPlayers = buildArrays(goals, assists, shots); // calls the function to build the arrays from the players.txt file 43 44 sortArrays(players, goals, assists, shots, numPlayers); // calls the function to sort the built arrays 45 46 printArrays(players, goals, assists, shots, numPlayers); // calls the function to print the sorted arrays 47 48 49 nameToFind = "Dustin Byfuglien"; 50 result = playerSearch(players, numPlayers, nameToFind, whereName); 51 52 if (result == true) 53 { _ 54 cout << nameToFind << " scored " << goals[whereName] << " goals and had " << assists[whereName] << " assists." << endl; diy.cpp 54 Info 725: Expected positive indentation from line 52 55 } 56 else 57 { _ 58 cout << nameToFind << " was not found." << endl; diy.cpp 58 Info 725: Expected positive indentation from line 56 59 } 60 61 62 return 0; _ 63 } diy.cpp 63 Warning 529: Symbol 'nameLoc' (line 24) not subsequently referenced 64 65 66 /*************************************************************** 67 Function: buildArrays 68 69 Use: Reads information from players.txt and sorts it into 70 3 different arrays. 71 72 Arguments: three Arrays, each will be filled with information 73 from the .txt file 74 75 Returns: the value of i, which is the number of elements that 76 were initialized during the building of the arrays 77 78 Notes: includes a loop that opens the file, and returns a 79 message of error if the file didn't open properly 80 ***************************************************************/ 81 82 83 84 int buildArrays(int goals[], int assists[], int shots[]) 85 { 86 87 int num, // declares num for use as variable to assign 88 // a value for each element in the array 89 90 i=0; // declares i for use as the counter of how many 91 // elements have been initialized and assigned 92 93 // declares a stream to read from players.txt 94 ifstream inFile; 95 96 // opens the file and runs a loop to check if the file 97 // was opened correctly 98 inFile.open ("players.txt"); 99 if (inFile.fail () ) 100 { 101 cout << "input file did not open."; 102 exit(0); 103 } 104 105 // Loop to build the arrays _ 106 inFile >> num; diy.cpp 106 Warning 539: Did not expect positive indentation from line 99 107 while(inFile) 108 { 109 goals[i] = num; 110 inFile >> num; 111 assists[i] = num; 112 inFile >> num; 113 shots[i] = num; 114 i++; 115 inFile >> num; 116 } 117 inFile.close (); 118 119 return i; // Value is the number of elements assigned to an array 120 } 121 122 /*************************************************************** 123 Function: calcTriArea 124 125 Use: sorts the arrays that were built from the buildArrays 126 function by ascending order alphabetically by player 127 name. 128 129 Arguments: four arrays, one is a string, the other three are 130 int arrays, and the int numPlayers which is the 131 amount of elements that were initialized during 132 the build function 133 134 Returns: nothing 135 136 Notes: This function also swaps each array according to each 137 swap that occurs with the player name array. 138 ***************************************************************/ 139 140 141 void sortArrays(string players[], int goals[], int assists[], int shots[], int numPlayers) 142 { 143 int top = 0, // Declares top to be used as the first 144 last = numPlayers, // Declares last to be used as the last element 145 ssf, // Declares ssf to be used as the smallest element 146 ptr, // Declares ptr as the number of elements 147 temp, // Declares temp, temp1, temp2, for swapping 148 temp1, 149 temp2; _ 150 string swap; // Declares swap as the variable for swapping diy.cpp 150 Warning 578: Declaration of symbol 'swap' hides symbol 'std::swap(<1>&, <1>&)' (line 120, file /usr/include/c++/3.2.2/bits/stl_algobase.h) 151 152 // Loops for the selection sort algorithm 153 do 154 { _ 155 ptr = top; diy.cpp 155 Info 725: Expected positive indentation from line 153 _ 156 ssf = top; diy.cpp 156 Info 725: Expected positive indentation from line 153 157 do 158 { 159 if (players[ptr] < players[ssf]) 160 { _ 161 ssf = ptr; diy.cpp 161 Info 725: Expected positive indentation from line 159 162 } 163 ptr = ptr + 1; 164 } 165 while (ptr < last); 166 167 // 4 different swaps for every time a player name is swapped 168 // the corresponding element in the arrays is swapped _ 169 swap = players[top]; diy.cpp 169 Info 725: Expected positive indentation from line 153 _ 170 players[top] = players[ssf]; diy.cpp 170 Info 725: Expected positive indentation from line 153 _ 171 players[ssf] = swap; diy.cpp 171 Info 725: Expected positive indentation from line 153 172 _ 173 temp = goals[top]; diy.cpp 173 Info 725: Expected positive indentation from line 153 _ 174 goals[top] = goals[ssf]; diy.cpp 174 Info 725: Expected positive indentation from line 153 _ 175 goals[ssf] = temp; diy.cpp 175 Info 725: Expected positive indentation from line 153 176 _ 177 temp1 = shots[top]; diy.cpp 177 Info 725: Expected positive indentation from line 153 _ 178 shots[top] = shots[ssf]; diy.cpp 178 Info 725: Expected positive indentation from line 153 _ 179 shots[ssf] = temp1; diy.cpp 179 Info 725: Expected positive indentation from line 153 180 _ 181 temp2 = assists[top]; diy.cpp 181 Info 725: Expected positive indentation from line 153 _ 182 assists[top] = assists[ssf]; diy.cpp 182 Info 725: Expected positive indentation from line 153 _ 183 assists[ssf] = temp2; diy.cpp 183 Info 725: Expected positive indentation from line 153 184 _ 185 top = top + 1; diy.cpp 185 Info 725: Expected positive indentation from line 153 186 } 187 while (top < last); 188 } 189 190 /*************************************************************** 191 Function: printArrays 192 193 Use: Displays a heading, and each of the categories from 194 the information of buildArrays. 195 196 Arguments: 4 arrays, players, goals, assists, shots, and an int 197 numPlayers 198 199 Returns: nothing 200 201 Notes: This function also calculates the points and shot % 202 ***************************************************************/ 203 204 void printArrays(string players[], int goals[], int assists[], int shots[], int numPlayers) 205 { 206 int d, // Declares d as the variable used for counting 207 numPoints, // declares the variable for number of points 208 numAssists; // Declares the variable for number of assists 209 double shotPercent, // Declares the variable for shot percent 210 numGoals, // Declares the variable for number of goals 211 numShots; // Declares the variable for number of shots 212 213 // Heading of information before the information is displayed 214 cout << endl << endl; 215 cout << " Chicago Blackhawks 2008-2009 Player Stats" << endl << endl << endl; 216 cout << "Players Goals Assists Points Shots Shooting %" << endl; 217 218 cout << "--------------------------------------------------------------------" << endl; 219 220 // Loop to display the stats for each player, as well as calculate 221 // the number of points and shot percent of each player. 222 for (d = 0; d < numPlayers; d++) 223 { _ 224 numGoals = goals[d]; diy.cpp 224 Info 725: Expected positive indentation from line 222 _ 225 numAssists = assists[d]; diy.cpp 225 Info 725: Expected positive indentation from line 222 _ 226 numShots = shots[d]; diy.cpp 226 Info 725: Expected positive indentation from line 222 _ 227 numPoints = numGoals + numAssists; diy.cpp 227 Info 725: Expected positive indentation from line 222 diy.cpp 227 Warning 524: Loss of precision (assignment) (double to int) 228 229 // condition that if number of shots = 0 230 // shooting percent is also 0 231 if (shots[d] != 0) _ 232 shotPercent = numGoals/numShots * 100; diy.cpp 232 Info 725: Expected positive indentation from line 231 diy.cpp 232 Info 834: Operator '/' followed by operator '*' is confusing. Use parentheses. 233 else _ 234 shotPercent = 0; diy.cpp 234 Info 725: Expected positive indentation from line 233 235 236 // Code to display each player information _ 237 cout << left << setw(20) << players[d]; diy.cpp 237 Info 725: Expected positive indentation from line 222 _ 238 cout << right << setw(8) << goals[d]; diy.cpp 238 Info 725: Expected positive indentation from line 222 _ 239 cout << right << setw(8) << assists[d]; diy.cpp 239 Info 725: Expected positive indentation from line 222 _ 240 cout << right << setw(8) << numPoints; diy.cpp 240 Info 725: Expected positive indentation from line 222 _ 241 cout << right << setw(8) << shots[d]; diy.cpp 241 Info 725: Expected positive indentation from line 222 _ 242 cout << setiosflags(ios::fixed | ios::showpoint) << setw(9) << setprecision(1) << shotPercent << endl; diy.cpp 242 Info 725: Expected positive indentation from line 222 243 244 } _ 245 } diy.cpp 245 Info 818: Pointer parameter 'assists' (line 204) could be declared as pointing to const diy.cpp 245 Info 818: Pointer parameter 'goals' (line 204) could be declared as pointing to const diy.cpp 245 Info 818: Pointer parameter 'players' (line 204) could be declared as pointing to const diy.cpp 245 Info 818: Pointer parameter 'shots' (line 204) could be declared as pointing to const 246 247 /*************************************************************** 248 Function: playerSearch 249 250 Use: checks to see if the name is within the array of 251 player names. 252 253 Arguments: array of player names, number of players, 254 string of name to find, and reference for location of 255 name 256 257 Returns: true if the name was found, and false if not 258 259 260 ***************************************************************/ 261 262 bool playerSearch( string players[], int numPlayers, string nameToFind, int &nameLoc) 263 { 264 int j = 0; 265 bool res; 266 267 while (j < numPlayers) 268 { 269 if (nameToFind == players[j]) 270 { _ 271 res = true; diy.cpp 271 Info 725: Expected positive indentation from line 269 _ 272 break; diy.cpp 272 Info 725: Expected positive indentation from line 269 273 } 274 else 275 { _ 276 res = false; diy.cpp 276 Info 725: Expected positive indentation from line 274 _ 277 j++; diy.cpp 277 Info 725: Expected positive indentation from line 274 278 } 279 } _ 280 if (res = true) diy.cpp 280 Info 720: Boolean test of assignment diy.cpp 280 Warning 506: Constant value Boolean diy.cpp 280 Info 838: Previously assigned value to variable 'res' has not been used diy.cpp 280 Info 774: Boolean within 'if' always evaluates to True [Reference: file diy.cpp: line 280] 281 { _ 282 return true; diy.cpp 282 Info 725: Expected positive indentation from line 280 283 } 284 else 285 { _ 286 return false; diy.cpp 286 Info 725: Expected positive indentation from line 284 287 } _ 288 } diy.cpp 288 Info 783: Line does not end with new-line diy.cpp 288 Info 715: Symbol 'nameLoc' (line 262) not referenced diy.cpp 288 Info 1764: Reference parameter 'nameLoc' (line 262) could be declared const ref diy.cpp 288 Info 818: Pointer parameter 'players' (line 262) could be declared as pointing to const diy.cpp 288 Warning 550: Symbol 'res' (line 265) not accessed diy.cpp 288 Warning 438: Last value assigned to variable 'res' (defined at line 265) not used

...note that I believe that this constitutes a fair use of their copyrighted work in as much as I quoted the source and recommend their products for those kinds of programmers for which their software targets and benefits. Check the Gimple Software site for more details about using their products.


MxB
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem executing nam-1.13 RodolfoAlvizu Computer Software Forum - Linux 20 28-Feb-2009 16:23
gzip linker problem boost::iostreams with zlib J-M C++ Forum 2 29-Apr-2008 05:00
Assigning string to NULL value amdrulz C Programming Language 5 10-Oct-2006 00:33
can anyone help me with this? chasey Java Forum 38 31-Jul-2006 11:33
a tester class and then some. postage Java Forum 1 06-May-2006 16:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:52.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.