jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't do:

float circum, circumference, radius, area2, area;
int main()
{

Do:

int main()
{
float circum, circumference, radius, area2, area;

and for your function:
(we could go wild and use doubles, but I'll leave it as float)

float circ(float radius)
{
        return 3.14*2*radius;
}

-OR-

float circ(float radius)
{
        float circumference;
        circumference = 3.14*2*radius;
        return circumference;
}

So the function takes a float (since that's what you declared your radius as in the main function, but could just as easily have been an int) and returns a float.
So back in main you need circum = circ(radius);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I missed it, but yours compiles because you declared them all as global variables. It works, but is not good practice for the purposes of clean coding: you should declare circumference, radius, etc within main and do the appropriate passing and returning.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The main function is supposed to return a status to the invoking program (e.g., the operating system) so when people have declared main() as returning an int and they say return 0; they really mean that the program executed successfully (there are other error codes used in specific circumstances where the execution has been interrupted). It is "doomed" because a C++ program abiding by the standard should have a main returning int. void main() is outdated.

For your second question, yes, but it's slightly more complicated than in C#. You still need a collection of some sort, but your collection must of the Standard Template Library variety (e.g., vector). Check out http://www.cplusplus.com/reference/algorithm/for_each/ to see all the requirements.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Circumference and area are both out of scope in the main() function, and you need to pass in radius to the function. They should probably return floats

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

With no braces,{}, your while loop is only getting the statement directly underneath it. Start there. You don't want to return a true or false from main as your return type for main is an integer but also doing so will halt your program. Instead, after your if statement, set a variable (so initiate it as false at the top and then set it to be true once your condition occurs) that you have defined under int ctr; (really you could declare it anywhere outside of the while loop and within main).
Then use your if statement to set this boolean variable if the value is out of range. Then make another boolean for values over 500 and yet another for those under 10.

Don't be so discouraged, programming like anything else takes time to work on and improve.

snehil_khanor commented: nice reply.. +1
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

Instead of simply counting the periods (dots) in the first if statement, why don't you store the location of the second one and remove it after the for loop exits? Your TextChanged() event will be firing each time you type anyway...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

you can also write using std::cout; at the top to cover every time you use it (or using namespace std; , but that's not encouraged as it defeats the purpose of having a namespace)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Firstly, you should be creating it as a Win32 console project.
Secondly, #include <iostream> , as iostream.h is non-standard. Start with those and it should give you two warnings and an error. The warnings are about using your two time functions with an _s at the end, which makes them safer from buffer overflows which can be a security issue down the line. You need a using statement to clarify your cout call.

P.S. find the errors in the output tab at the bottom of the screen, after you've run your build

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to either pass in your fin into PrintArray, or more likely create a new ifstream object. Same with your j and k of the PrintArray() (the first one). They don't exist in the local scope (skim back through your text to clarify this for yourself). For these you can create a new local variable within that function.
Also, you are trying to overload a function PrintArray() with the same signature (i.e., int,int,int,ofstream&,int). How will the compiler tell the difference between the two? (it seems like you meant the one that returns ct to have a return type)
And, you don't need the return statements in your void functions.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please put some code tags around it code /code (in brackets []) or highlight and hit the button on the toolbar of the editor

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The editor I'm using is pico. Thanks for the link Jonsca, I can get the file now, but the code is all in one line, is there a way to keep the indentions without having to manualy go back and do it myself?

There are converters (see http://en.wikipedia.org/wiki/CRLF for the reason why this occurs) but it's probably faster to do it by hand unless there are thousands of lines...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The editor I'm using is pico. I'm sure there is a way to simply open it up in wordpad, but like I said I'm a newb and I don't really know how.

I just tested it with putty now, highlight and hit control-C. There's also a command in the system menu in the upper left corner for Copy All To Clipboard, but that gets all your login stuff too and didn't get the Pico session when I tried it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Get a secure FTP program (e.g., http://www.coreftp.com/ but there are many others, or if your school doesn't use SSH you could use the insecure one in windows,ftp.exe ) and you should be able to log into your shell account and transfer files.

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

It costs and I've never used it but just to throw it out there:

http://www.comeaucomputing.com/

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
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 mean, istaller that will need to download nothing from Net
I cannot see such stuff in the link. am I missing something?

Apologies, I meant that you could go to the sourceforge page and download the .tar.gz files and then install them by hand using their instructions on that page. Unfortunately, when you click on the sourceforge link on the page I gave you, it defaults to having the Installer versions expanded, but if you scroll down another inch or two you can expand either GCC Version 3 or 4 (depending on which one you are using currently) and get the .tar.gz(s). Then the instructions should be appropriate to those files and you shouldn't have to do any further downloading (you can grab all the packages for C++, etc. so you can install those offline too).

Good luck with it. Hope this is what you were looking for.

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

Hi all,
can anyone point me to an offline MINGW installer?

I've never attempted to install it this way, but check out (scroll down to Manual Installation) http://www.mingw.org/wiki/HOWTO_Install_the_MinGW_GCC_Compiler_Suite

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're calling main at the end of your function and you shouldn't be.

The problem with your arrays is that you are trying to go from yData[xMin] which may not (and in fact does not in this case) contain the proper values. I might think about deriving yMin and yMax from y = xMin*m+b and y = xMax*m+b respectively.

There may be an issues with all the floats and ints around. Instead of declaring some of them ints to fit in with your loop schema, you may be better off casting from float to int (beware rounding) when you have to.

You're most of the way there... test your example for more cases, e.g. decimals.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't need ; after your #includes

You need a return type for your function definition (and you can omit the return)

>= and <= are the only valid ways of writing those operators

you need to give an array size for xData and yData

just follow the errors that you get and start from the top of the list and correct them...

you need to move the counter along by one and save "dumping" your x,y value arrays until the end. you can transform your while loop into a for.

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

#include <iostream> not iostream.h
(and using namespace std; or preferably using std::cout; using std::cin; )

main should always return an int

As it is you are trying to cram your movietype string into a char... pay close attention to your error message, what is it saying your type needs to be? Remember a string is a character array with a '\0' terminator

p.s. if you've covered it in class, you could just use a string and be done with this mess

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A great place to start (particularly if you're looking for implementation details) is http://www.x.org/wiki/

There are loads of other sites that can give you specific info on XLib in C++

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why is your customers() returning char?

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

you're very welcome. mark the thread as solved if you're all set.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Should be either

int x = 153;

or

int x;
x = 153;

if you wanted to declare two different variables on one line you could put:

int x,y;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See: http://msdn.microsoft.com/en-us/library/h21280bw(VS.80).aspx
For the implementations of \n and \r\n on different systems (Win vs. *nix, and others) see: http://en.wikipedia.org/wiki/Newline

But basically,
\b is a backspace and \r is carriage return

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure which thread library you are using, but even without it you are missing an #endif at the end of your header. I'm not sure if that's the main issue. Are there other errors besides the ones you pasted in?

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

I'll have to put it through some further testing to make sure, but it looks really good. Thanks for the extra assistance.