jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a look at an ASCII table: http://web.cs.mun.ca/~michael/c/ascii-table.html how do the two cases relate?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also, I don't think cin is getting all your numbers in a row like that. I'm trying to reformulate it with a while loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your counter values do not exist outside of the loop scope
e.g.

void getData( int compMenuList[], int counter1)
{
	counter1 = 0;

	cout << "Enter the menu choice(s): ";
for(counter1 = 0; counter1 < 7; counter1++)
	{
		cin >> compMenuList[counter1];

		if(compMenuList[counter1] = -999)
			break;
	}
}

Firstly, counter1 should be passed in by reference void getData( int compMenuList[], int & counter1) since you use it in your other function. But even if you take it in, you use it in a loop as a local loop variable and it's out of scope by the time you would be returning the function. You then tried to use this in PrintCheck and your loops were not being run since your final loop condition was zero. That way you ended up with whatever junk was in memory at the address of the structs. So the solution is to increment it as a counter (counter1++) within the body of the for loop so the value is preserved. Then change the for loop in the Print function to i<counter2 and j<counter2 (not <= as you had it)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why not change calculateAverage to return a double (so your average isn't truncated) and call the function in place from your "out" processing.

double CalculateAvg (ifstream& students, string studentid[60], string fname[60], string lname[60], int Q1[60], int Q2[60], int Q3[60], int MidTerm[60], int Q4[60], int Q5[60], int Q6[60], int Final[60],int i)
{
    return ((Q1[i] + Q2[i] + Q3[i] + MidTerm[i] + Q4[i] + Q5[i] + Q6[i] + Final[i]) / 8);
   //scratch my earlier response, you want to pass in i to get which student to average
// and the fact that you were reading in stuff in this function was "using up" lines of your file		
}

and

out << left << setw(13) << studentid[i] << setw(12) << fname[i] << setw(8) << lname[i] << setw(7)<< Q1[i] << setw(7) << Q2[i] << setw(7) << Q3[i] << setw(7) << MidTerm[i] << setw(8)
<< Q4[i] << setw(7) << Q5[i] << setw(8) << Q6[i] << setw(8) << Final[i]<<CalculateAvg (students, id, fname, lname, Q1, Q2, Q3, MidTerm, Q4, Q5, Q6, Final,i);

That way you have the calculation the way you want it and can format the return value in whatever way you want.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

void updateFrequency(int size, char grade[],int A,int B,int C,int D,int F) should have ABCDF passed in by reference as in void updateFrequency(int size, char grade[],int & A,int & B,int & C,int & D,int & F) so that when you are modifying the counts in the function they are changed in main().
Call it as: updateFrequency(size,grade,A,B,C,D,F)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Get rid of infile>>row>>col; on line 39, it's reading in 0,0 and throwing it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

OK, I gotcha now. Well you still need to assign something to the bacteria[row][col] for it to show up in your array.

while(infile>>row>>column)
           bacteria[row][col] = 1;

will work. But as part of your design considerations you need to decide what you want those cells to be -- is integer best, or boolean? In other words what will "store' the state of the system the best between iterations.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is a 2D array the best choice here? You have more than one value corresponding to each "row" number?

infile>>row>>col;
    
     while(infile)
     {
     bacteria[row][col];
     infile>>row>>col;
     }
     infile.close();

should probably be something like

int i=0;
while(infile>>row>>column)
{
           bacteriaX[i] = row;
           bacteriaY[i] = column;
           i++;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This doesn't preclude that. In your outer one you exit from while via the return statement. This one, the break will only exit out one layer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Move that entire line 6 out of main and put it before and outside of main.

Also, main() should always be int main(), returning 0 at the very end

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm sure there are more elegant solutions to this problem, but here's an example I thought of

bool exitloop = false;
switch(ch1)
{
   case 1 :{
       while(1) {
           cout<<" Directory Selection"<<endl;
            cout<<" 1. Computing Science "<<endl;
            cout<<" Enter your choice : ";
            cin>>ch2;
           switch(ch2){
               case 1 : break; //out of inner switch
               case 4 :exitloop = true;  break; //out of inner switch
           }
        if(exitloop)
	   break;  //out of while
       }

   break;  //out of outer switch
	   }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
mi = KM_MI * km;           
gal = L_G * l;

should probably be

mi = (1/KM_MI) *km;
gal = (1/L_G) *l;

because the units should cancel out in your multiplication
mi = (mi/km)*km = mi
gal = (gal/L)*L = gal

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if the index is zero it has to be a<y and ctr<y in your for conditions, and the program shouldn't go past your first entry of a grade due to the above. And no, it's not the compiler :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Still have the grade[x] in there... take the x out of your variable declarations so you can't use it by mistake.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

it has to be for(int variable = 0;variable<number;variable++) that way you go from 0 to the number-1 element of the array (as a a[4] has a[0], a[1], a[2], and a[3]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It needs to be int grade[10]; it can't be string if you are going to do calculations with it. If you only have one g you're writing over it each time. And that course[x] should be course[a]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
for(int a=1; a<=y; a++)
{
cout<< "Please enter your course " << n << ":";
cin>> course[a];
cout<< endl;
cout<< "Please enter your Grade: ";
cin>> grade[a];
cout<< endl;
n++;
}

Also note that arrays start at zero.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well your cins and couts are using a variable X which is never changed in your program. You should use the loop variable as your index.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

grade[] is an array of strings, it should be ints or doubles

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Worked for me even without the const on g++ 3.4.2. Was it crashing on you when you tried to run it at that point?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Pop a cin.ignore() between lines 32 and 33 (your input was getting corrupted, that throws out anything left over).

Also, don't redeclare answer on line 28.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Summary of all of the above:
change poly to

void poly(vector<double> A, vector<double> & B, double x, double& p, double& px, double& pxx, int & degree);

(and if you need A for another segment of your program change it to a reference too)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I knew when I wrote that that it probably was not right. It has nothing to do with your iterations count but it's crashing in your f() method. You're passing in degree and it's garbage (I think because you needed to pass it in by reference to the poly function) and your actual B vector is of 0 length. EDIT: nevermind lol

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How many iterations are you putting in? It may be greater than the maximum value for an integer on your machine ( I only say that because you were starting at the millions before).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Unless you are doing something with real time OSes (http://msdn.microsoft.com/en-us/library/ms838340(WinEmbedded.5).aspx), and even then it's impractical, it will be obsolete knowledge. inp/outp used to be great for interfacing with fixed address ISA cards. If you're interested in this kinda thing check out the DDK (http://www.microsoft.com/whdc/devtools/wdk/default.mspx).
Not to be a wet blanket about it, just offering some advice.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

how is the size of AllianceCharacters[] determined? You probably need a "new" statement to instantiate the entire array (in addition to its members, which you have done in your method)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Wow that's like a 3-way tie there...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Pop int Counter::nCounters; at the top of your counter.cpp file.
http://www.cs.loyola.edu/~lawrie/CS301/F03/StaticClassMembers.htm

Also, you don't need to include your cpp file in your h file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I made a couple small changes to make sure that we are only updating hangman for wrong guesses. This works on my machine.
(ignore the strcmp_s change,it's a good idea...I was compiling on another sys initially)

#include <iostream>
    #include <windows.h> //has sleep function
     #include <string>
    using namespace std;
     
    void DrawBar(int guess);
	
    int main()
    {
        char solution[8]; //holds solution
        char blank[8]; //holds "*"'s for unsolved letters
        int counter = 0; //general-use counter
        int right = 0; //1 = right guess, 0 = wrong guess.
        char guess;
        int word=0;
	bool found;
        cout<<"Enter phrase 8 chars or less."<<endl;
        cin.getline(solution, 8);
        int puzzLength = strlen(solution); //finds lengtrh of puzzle, stores INT value to puzzlength
         
    //convert puzzle to full uppercase
    for (counter = 0; counter < puzzLength; counter++){
       solution[counter] = toupper(solution[counter]);
    }
    //done converting
      
    strcpy(blank, solution); //copy solution to the 'blank' array
      
    for (counter = 0; counter < puzzLength; counter++) { //converts characters to _'s to represent blanks
      
       if (isalnum(solution[counter])) blank[counter] = '_';
	   
 
       else blank[counter] = solution[counter];
        
    } //closes for loop
        
    while (strcmp(solution, blank)) { //play game until the 'blank' puzzle becomes the 'right' answer
       
    cout<<endl<<"Solution phrase is: "<<solution<<"."<<endl;
    cout<<"The current 'blank' puzzle is: "<<blank<<"."<<endl;
    cout<<"Enter a guess."<<endl;
    cin>>guess;
    guess = toupper(guess);
         
       
    //cbeck guess!
    for (counter = 0; counter <= puzzLength; counter++) {
        
        if (guess == solution[counter]) {
        blank[counter] = guess; //fill in the puzzle with the letter
        found = true; 
        }
	
        } //close loop, done checking guess
         if (!found)
		 word++;
	 found = false;
	
	DrawBar(word);
	if(word >=5) break;
        } //game is over.
         if(word …
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Did you change both the declaration and the definition of DrawBar to void DrawBar(int guess) ?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would do it within the while loop after the for loop.

You have it after the whole thing is over. That does you no good.

//cbeck guess!
    for (counter = 0; counter <= puzzLength; counter++) {
        
        if (guess == solution[counter]) {
        blank[counter] = guess; //fill in the puzzle with the letter
         
        }
         
        } //close loop, done checking guess
         
	word++;
	DrawBar(word);
        
        if(word >=5) break;
        } //game is over.
         if (word >=5)
             cout <<"Lost"<<endl;
         else 
              cout<<"Winner!";
        cin.get();
        return 0;
       }

declare word at the top of main

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Does your function have to be void? If not change it to double and do return average; To fix it as is:

cin.ignore();
for (int i=0; i<5; i++)
	  {
            
            cout << "Please enter grade" <<endl;
            cin >> grade[i];
	    sum= sum+grade[i];
	   }  
                 average = sum/5;

Your name input was mucking up the input stream.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It has nothing to do with guess. Don't mess up the working part of your program. At the top in main() declare int guesscount; After your for loop for(counter =0.....) we've made one guess, so guesscount++; (make sure it's outside of the for loop). Next, call DrawBar(guesscount); However, you'll need to put a condition for greater than 6 in your drawbar because what if it takes the user 6 guesses or more? As it is the program will bypass all of your else if statements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would do it within the while loop after the for loop. Why would you change guess, you need that to be a char. Declare a new int, increment it (++) at the end of the while loop and then call DrawBar(countervariablehere). That way your user knows their status after they've made their guess.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Exactly. You just want something that's going to keep track each time through the while loop so you can register what guess your user is on.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Actually, take the final average calculation (average = sum/5) _outside_ of the for loop otherwise you'll be calculating it each time.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Nope, just have an int that increments with your while loop. You'll have to decide the best place to call DrawBar as it could be reflecting the status after this present turn or showing the user their status before the next guess.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're passing a char into your DrawBar() function which is incorrect. Keep a separate int counter to keep track of your guesses and then give that to Drawbar after a guess. You'll never be entering in the characters '1' '2' '3' '4' '5' as part of your alphabet guesses so there is no sense using what would be nonsense anyway.

Also, next time please think of a meaningful title for your post. Not meaning to single you out, but I wanted to say something. It takes 2 seconds and believe it or not people are much more willing to help when they can see what they are getting into.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

My guess would be that you needed to qualify fixed in your code with the ios:: namespace if you didn't have using namespace std; in your code (which you shouldn't do anyway). I'm not entirely up on how ios and iostream are woven together, though I think ios is the base class.
In this example, using setf in place of the manipulator "fixed" basically accomplishes the same thing, changing the flags to reflect that the output should be fixed-point.

In terms of the general concept, look around about namespaces and the using directive (there's a lot on this site as to why you shouldn't bring the entire std namespace in). There are lots of examples of how to use it more effectively with e.g., using std::cout; so you don't have to qualify the often-used method.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Declare Node<L>* ptr; inside your method but outside the else block. Then inside of else set *ptr = first; You might need to change what you return but I'm not absolutely sure.

MooAndStuff commented: Solved my problem =) +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try it as:

cout.setf(ios::fixed);
cout << setprecision(1) << "Mean: ";

Instead of: cout << fixed << setprecision(1) << "Mean: ";

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.nrbook.com/a/bookcpdf.php section 9.4 (you need some stupid plug-in in addition to Acrobat Reader but if you're in this line of inquiry this book is gospel). It does not provide a clean answer to this but does have a calculation for how much the error changes at each step. It's just a matter of how precise your answer needs to be. Data is usually available for the tolerance of doubles and long doubles on a given compiler/machine. Sometimes the best solution is to test out your implementation with a poly that you already know the answer to and see how quickly it converges. Hope that helps a bit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I had tried Ancient's suggestion and wasn't able to get it to work (but it's a sound idea so it's more than probable that's on me) but when I took your example .txt file and removed the spaces from the strings (you could replace them with underscores which would be easy to strip for use in the program) it works with savedGame >> armorName .
Here's my output from your program.

25
25
10
2
13
12
11
0
IronShortSword
3
2
0
SoftLeatherArmor
2
2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

sizeof( any pointer ) is always the same -- sizeof returns the number of bytes it takes to store the address of the pointer, not the length of the string the pointer references. So lines 12 and 13 of your code will always return the same value (probably 4).

line 14: you are attempting to store an unitialized pointer into the vector. undef points to just some random memory location, and that may cause a seg fault, especially if you later attempt to do anything with that pointer.

It was meant as an illustrative example more than anything... line 14 was my attempt to reproduce his error which did manifest but I understand your point about it failing in the future.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was able to run the following code on my machine. Word* has the same size as char *. I don't know if maybe I'm missing something or if the conditions are different (I'm using gcc 3.4.2 in Vista64).

#include<iostream>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
int main()
{
	vector <char *> charvec;
	char * undef;
	char * word = "statement";

	cout <<"Char*"<<" "<<sizeof(char *)<<endl;
	cout <<"word"<<" "<<sizeof(word)<<endl;
	charvec.push_back(undef);
	cout <<"undef push succeeded"<<endl;
	charvec.push_back(word);
	cout<<"word push succeeded"<<endl;
	return 0;
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't use the getline methods, just redirect from the stream as you would for any of the other variables (e.g, savedGame >> weaponName; and same for armorName). If you are writing the files manually it's finicky about the booleans (requiring 0 or 1 representation, I think I didn't explore it further). AFAIK, you can chain all those inputs into one statement with savedGame >> var1 >> var2 etc etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

tally[i+2] != tally[i] || tally[i+1] (line 34) is not doing what you want it to do. You need (tally[i+2] !=tally[i]) || (tally[i+2] !=tally[i+1]) .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

in a class (or struct)
where c is a pointer to said class and member is a public method of c (can be a public field also)
c->member()
is the same as (*c).member()

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Except you need to move the average calculation outside the for loop so it's not done each time. You should cast total to a double before the division so that your average isn't truncated.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'd change them all to link rather than risking collision with that other header file (which is probably the non-standard STL list header)