jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of it is your header is link.h and you include "list.h" (which even though it's in quotes, it ends up finding some older header called list.h in the search path). There's some stuff with your node class too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Maybe I'm missing something, but do you actually create myIntList (instantiate your List object) before you attempt to use it in main()?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.cplusplus.com/reference/iostream/manipulators/setw/
That way the widths of your fields will be constant and you can use your ostream directly without all that mildly stressful string manipulation.

yatman commented: excellent help! +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to change all the variables in inputfn to references, otherwise you'll just have whatever garbage is in those locations after they are initialized. EDIT: file IO seems to be ok.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Namespaces are important, but for the sake of a school assignment you could probably put using std::cout; and using std::endl; instead. Then you'd have to specify for the std::ofstream , etc. But I do concede to your point Stu and agree that good habits are important at any stage of the game.

StuXYZ commented: good comment on using (well you agreed with me :) +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why are you calling resultsfn with only 5 parameters when it takes 11 in your prototype and definition? It will not assume defaults for those. Often what the compiler says, goes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a p-code skeleton. If you're still having trouble, figure out what it takes to print just the stars on separate lines with the right count, then figure out how to print out the spaces with one star at the end of each line. Then combine the two.

for loop (stepping through the lines)
{
          if(above the midpoint)
              {number of spaces =
                number of stars =  
                }
           else
               {  number of spaces =
                 number of stars =  
                }
          for loop (using number of spaces)
                  print spaces
          for loop (using number of stars)
                  print stars

         Now print an endl to go to the next line.
}

This is one of those times when putting it out on paper can help too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You still have the endl (s) in your code. You need to get rid of those otherwise you will be printing out stars and spaces with a carriage return line feed after them. Here's a hint - on the way down you're subtracting one space, once you get to the halfway mark you are adding a space. In other words pop in some if statements. Don't be afraid to try a bunch of different things, you'll learn a lot that way.

In the future, don't just ditch your post for a new one, as adding a reply to it will bump it up on the list anyway.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's another inconsistency when you are trying to dereference your struct members to write to them with cin. First, for multiple accounts you are not using the i value anywhere in your loop. So you need x to dereference your array pointer and then you can just use the dot operator, e.g. x[i].name to get the name element.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I found this... Honestly I'm not sure I understand it completely.

http://gcc.gnu.org/ml/gcc-help/2008-01/msg00137.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Scratch... sorry. I think he's right with the while, except use your count variable. You were getting stuck since your for loop wasn't incrementing itemsOrdered but even doing that your count would be off. Go for the while or do{} while().

(when writing this I had missed that itemsOrdered was a char, but you got it to work so good luck and hope we at least nudged you a bit in the right direction :) )

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

But why does your function return an int if you want it to return a string? Was your assignment given that way? Just saying it doesn't make much sense. If you need to return a string, just change the return type of the function string myName() { etc. }

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why can't myName() return a string instead of an int? Also, the restriction on cout seems to be for your function body only.

Great post title, BTW.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

And, you're very welcome!!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First, declare ofstream report; within main() so it's not global. Then, for your function output_info, pass report in by reference (so you'll have to change your declaration of output_info to report this). Make sure you do the opening of your file within main() first before you pass it into anything.
Now anywhere there is a cout at the present (so cout << "ID number:"; becomes report <<"ID number:"; . Any other functions that need it, do the same thing, pass that ofstream report in by reference.

The direction of your << or >> operator should reflect whether you are taking data into a variable from a stream or outputting to a stream.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should just be able to substitute your ofstream object for the cout directly. See http://www.bgsu.edu/departments/compsci/docs/write.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

declare a variable as count at the top of main (what would be a good type for that variable if it's going to hold 0,1,2,3...), set it to zero. Each time your condition is met (so when your if statement is saying yes, the users input has matched the desired value), increment your counter (that is, assign the value of variable+1 back to variable).
At the end, cout << count<<"/3 \n"; If you get stuck, post back, but flip ahead a few pages in your text too. I know you may not have covered the topics yet, but you probably can create it out of stuff you are already familiar with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put a counter in with the (appropriate) if statements you've already defined (when a match happens, register one more on the counter). In the end, output the counter.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Explain your confusion a little more. Wouldn't you just add up all of the product[index].sale values then prompt the user for a payment amount?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Have your constructor for Gradebook take two parameters, one for the student's name and one for the professors. As you have it, you are setting both the student and professor name to be the name passed in:

GradeBook::GradeBook( string name )
    {
        setCourseName(name),
        setProfessorName(name),
        displayMessage();
    }

should be something like:

Gradebook::Gradebook(string coursename,string profname)
{
            setCourseName(coursename);
            setProfessorName(profname);
            displayMessage();

}

and change the declaration to GradeBook( string,string );

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I see your point Ancient. I guess I supposed that passing a running total and a number of scores into a function constructed thusly might be just as valid in this context.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, your int n; is local to that block so it's going to disappear shortly thereafter. A lot of this depends on the specification of your problem. Can you use arrays? You don't have to, and it's more effective without them, but if that helps you understand then go for it. Write out an average of a set of numbers on a piece of paper and see how you do it, step by step.... i.e., add numbers up, divide by count of numbers, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I tried a bunch of things but none worked out.... the compiler seems to want a Node* (*)[MAP_HEIGHT] but putting that in explicitly didn't do it

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're very welcome, glad I could help.

It might be a safe choice to put in i < min(testData.size(),trainingData.size()) for your for loop condition to make sure you don't get a mismatch.
If you wanted to get fancy, and with more data, you could take a random sample of your training set equal to the size of the testing set. That's the only way I can think of offhand.

bpt0004 commented: Your a LifeSaver!!! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

TestDataVector is declared locally within your else block. Once the else block completes it's out of scope and destroyed and there's nothing to return (I had missed this before).

So just move it to the top of your method and it should work (bearing in mind that it still crashes now because you have more training data than testing). So take that into account or make more testing samples.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There's no testing data! I thought I was checking for it before but it was just reporting the training data sizes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Double check the sizes of the vectors in the vector<vector<int> > make sure they are not zero. Also remember that you have a mismatch between the size of your training and testing sets so if you are iterating over both your testing set it going to run out. Keep printing out your iteration step by step until it crashes...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is probably your best bet:
http://www.cplusplus.com/reference/iostream/istream/ignore/
(with a newline as your delimiter)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

For some reason you are getting a vector of length 0 at the beginning of your training data (I'll look more closely later) and one at the end of your testing data. When it tries to step through the 0 length vector it chokes. I looked through, but are you clearing a line out somewhere? At any rate, as a band-aid you could scan your data and delete any zero length vectors so that you can keep going with the program but it's definitely worth your while to delve into it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you can take the parens off of the hours>3 and hours>11 individually and put a set around the whole thing

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You've stuck a ; on the end of your else statement in your function, so it's interpreting the rate = max_rate; in isolation. So that's what your function is returning each time.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Because if you have no return value for your function you are getting whatever garbage was in rate to begin with

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use code tags

around your code.

double hours; rate;

separate on the same line by a comma: double hours, rate; or if you want do double hours; double rate;

rate = calculatecharges(double hours);

don't need to give the variable type when calling the function
(but you do in the declaration or definition

double calculatecharges(double hours) ;

should not have a semicolon after it

rate=base_rate;
       else if (hours>3)
       rate=((hours-3)*long_rate + base_rate);
       else (hours>11)
       rate = max_rate;
       }

Your function returns a double but you are not returning anything in this case. Also, the rate in your main() is not in scope here (reread that section of your text if you're not sure why). You should calculate it in here and then return it, and you've already got it set up correctly in main.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post up the main that you are using to test it?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're really close (at least with this part)...

for(int i=0; i <trainingData.size() ;i++)
     {  
        count = trainingData[i].size(); //can make this trainingData[0] if guaranteed same size
	for(int j=0; j <count ; j++)
        {                  
            addedSum= addedSum+ (trainingData[i][j]-testData[i][j])*(trainingData[i][j]-testData[i][j]);
        }

	returnvec.push_back(sqrt(addedSum));   	         
         
      }

I didn't have a chance to check it thoroughly but I'm sure you get the basic idea. I wrote the square out (you can leave the pow in if you want) but you really don't need the fabs cause you are squaring the value anyway.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i'm getting a run-time error running the code which causes the program to crash.

running the gdb debugger i get a "An Access Violation (Segmentation Fault) raised in your program" on this line

addedSum= addedSum+ pow( fabs(trainingData[i][j]-testData[i][j]),2);

sry I missed it before but count for one element should be equal to trainingData[currentindex].size() (or however you are going to designate the "active" training set vector -- theoretically if all your vectors are going to be the same size you could take trainingData[0] but that's not as extensible) and then iterate over the entire set using another for loop.
the way you have it, your for loops are trying to sum the squares over the size of the _entire_ training set, whereas you want to perform the calculation using just one of the vectors at a time).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Other than the fact that you don't need to calculate distance until after the for loops complete (you probably left it in there to debug at this point) and you don't need fabs since you are squaring, it seems to be ok.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Based on how you've set it up, your vector<int> for each sample will have two members, say V1(0) = 1, and V1(1) = 2, and another would have V2(0) = 2, V2(1) = 3. So you are correct that you would have to calculate a third vector V3(0) = V1(0) - V2(0)=-1,V3(1) = V1(1)-V2(1) = -1. Then you could iterate through the vector and square all the members, then take the square root (root 2 in this example). Return a vector<int> of all of the Euclidian distances(make sure the index in the distance vector lines up with the corresponding training data).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you are assigning your temps TO the record.totalpoints when the temps haven't been assigned any value.

also, your temp1,temp2,temp3 are not in scope with the class_avg function. pass them in as arguments. you should only need one while loop, if there is just a set number of records, use a for loop.

it's easy to get overwhelmed, but just take a step back and sketch it out on a piece of paper

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
cout << "The selling price of the dress is " << ch << percentage << endl; //Step 6
sellingPrice = price + (1 * percentage);

you should be calculating selling price before you display it (as of now you are saying it sells at the percentage you entered)

sellingprice should just be (1+percentage/100)*price, you probably just glanced over it....

p.s. please use code tags

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

iQuickAnswer should be a char. it can technically be an int, but that might mess up your comparisons.
also, if you are testing for 'y' you should probably test for 'Y' also (iQuickAnswer == 'y' || iQuickAnswer == 'Y'). the same for 'n' and 'N'.

your syntax is laid out correctly, but to reassure yourself about your nesting you could put all the optional braces in to delineate your "if/else if/else" groupings.
There may be other errors, but that's what I got from a quick glance.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster