jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just move line 63 outside of the loop if you want the largest to print only once. I still don't think that's going to get you what you need though. If you've already printed the number out and a smaller one comes along how will you account for that?
Honestly, you're making this difficult on yourself. The sort takes 5 lines and you won't need lines 53-63 anymore. If I were giving this assignment that's what I would be aiming for.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put the curly braces like Nick Evan was saying. If you don't have the braces only the statement immediately below the if statement is associated with it. Put braces around lines 28 to 30. Now that whole grouping is associated with the top if statement.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
previousSmallest <= smallest;
smallest <= largest;

These two lines are not doing anything (they compile but as statements it will only evaluate to true or false and have no effect).

I would still sort them in the function and just print it out with a loop. You're just printing out what is currently the smallest as you traverse the array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also: curly brackets! They're more important then you think.

We're working our way up to that.

@OP: No, you can only use the comma for variables that are of the same type.

char choice;
int weight;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just do a simple bubble sort. See http://www.cprogramming.com/tutorial/computersciencetheory/sorting1.html for an example.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How did you declare it as a char? Change it from being a char to an int.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

weight should be an integer and not a char. You were comparing the ASCII value of the first character (so if you typed in 70 you'd only get the 7 as a character variable holds exactly one character, and 7 has an ASCII value of 55 which is less than 60).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

doesnt work, it comes up with some error msg saying before else


and heres the full code

Can't be the full code, where is weight declared? Paste your exact code, don't try to paraphrase.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I never seem to have any soda ash around the house when I really need some though....

Also, is there a microwave version?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could you post the complete code? The error is not apparent from what you have posted.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Wait, who are you again??

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Somebody else can probably illuminate this a little bit further, but there really is a y1 declared in math.h. It appears to be associated with an older version of the complex type(?). Seemingly, if you #define _NO_OLDNAMES before you #include <cmath> it should disregard those declarations. I couldn't tell you if this is a bad idea for any reason or not. Unless it's critical to your code it might be advantageous to just rename it (and an opportunity to make it more descriptive :) )

EDIT: Wow, the posts all cascaded over one another

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

here are my answers..plzzz check them for me.

Here's a wild idea. What happens when you run them in your program? Do they work there?

And "plzzz" use code tags:

[code]

//code goes here

[/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

And the money machine is already working. There's going to be a "new" version released soon, which will be identical except it's 6 minutes longer.
And no doubt the crowds will once again flock to the cinemas and DVD stores to buy that one too even though they already have the original.

Well no doubt they've also unearthed 16 hours of promotional BS that had sat on the cutting room floor until someone figured out "Sigourney Weaver's What I Ate for Lunch Diary" might be of interest to a die-hard fan. You should come to expect this by now...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

thanks Ancient Dragon,

really? thank for your info, i didn't notice it but everytime i start dat program it'll keep remind me that 20 more days left...i think to

Sorry to bump your solved thread, but go to the help menu and the 6th option down is "Register Product". Do their little dance (ultraeasy if you already have hotmail or other M$ stuff) and that message will go away.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

> I got 3.13!
I got 3.1415926535897932384626433832795
I found the test as easy as pie ;)

Hey, I got in with the "e" reference first. There's only so much room for irrational numbers in this town. ;)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I had never noticed that but yes, it certainly works.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Next time please use the code tags

[code]

code goes here

[/code]

Why do you declare choice after you try to write to it? You need to move int choice = 0; before std::cin >>choice;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Select the whole Form1 window in the designer (not the webbrowser bit) so on the properties window at the top it should say Form1 (or whatever you called it)

restrictment commented: Thanks for the help! +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Go to the designer in your application and click on the Form1 window (or whatever you named it). Go to the properties menu on the right (if it's not there go to View/Other Windows/Properties Window. Click on the lightening bolt to get to the events. Go to load. Double click the empty cell next to it. An event handler will be inserted into your code. Within that type webBrowser1->Navigate("http://www.google.com"); (specify the name of your Web Browser object) Now when your form loads you will get google (or change it to something else -- or as a special exercise let your user specify it as an option ;))

EDIT: I'm not clairvoyant lol -- I've been through a similar tut in C# eons ago. But AD is right and you posted your code anyway, I just lagged behind everyone.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You probably don't need the .exe extension, but you shouldn't use the extension .cpp? Your .cpp file is just a text file. The compiler takes that, compiles it and links it into an .exe.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What are you typing in to execute the program you've written?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a stringstream object:

#include <sstream> 
//...
stringstream ss;
double value = 10.4567;
ss<<value;
string valuestr = ss.str();

There are certainly other methods that will work but this one is more straightforward IMHO.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

,use "b"and"d"variables for base and decimal respectively.

Wow, well... if you've gotten that far with it then by all means. I was kind of thinking of going with b for decimal. I'll have to go redesign...

mitrmkar commented: LOL +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

And I made jwenting say that with my Jedi powers (forget anything scientific).

The test was too obvious the way it was laid out (still my score was just about "e" which gives some logarithmic significance to my answers).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Looks like there are a couple of methods. I didn't play around with it much further than this:

array<Point>^ ptarray = gcnew array<Point>(3);
ptarray->SetValue(Point(0,0),0);
ptarray->SetValue(Point(1,1),1);
ptarray[2] = Point(2,2);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not too far off.

With c-strings (strings terminated in '\0' as opposed to std::string which I'll get to in a minute) the variable is essentially a pointer, so saying

char * str1 = "Hello"; //a '\0' is automatically appended at the end of each of these
char * str2 = "Hello";

asking str1 == str2 will come up false every time because the pointers are not equal, they are stored in two different spots in memory. This same idea holds true for character arrays. Hence there's a need for a function like strcmp which does all the finagling for you.

On the other hand, std::strings, when you have

#include <string>
std::string mystr = "Hello";
std::string mystr2 = "Hello";

mystr == mystr2 will be true because the std::strings have an overloaded == operator (essentially a custom recipe specific to the class as to which components of the strings should be compared against each other).

Switch statements in C++ (and C) can only take ints (as well as chars which are basically 1 byte integers, and enumeration types which are implicitly converted to integers). It's been a while since I used VBA but it might be closer to .NET, where like in C# you can use strings in a switch statement.

I've probably glossed over some important points but others will be able to clarify if necessary. I may have known the internals of some of the string functions at one point but I …

daino commented: Great Answer +3
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have to make a decision based on the options Lerner gave you in the last paragraph. At this point there is no right or wrong answer.

At that point make a function skeleton like:

return_type myfunctionname(type param1,type param2)
{

}

See how much of it you can fill in on your own. Then post back what you have.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This also means you'll need to overload << for your poly class.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I went back and looked it over again. I edited my post but you got there first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

EDIT: Ignore the other part about ostream. Since n and d are private members, you must access them through some kind of "getter" function. If they were public you'd probably want something more like r.(*n) instead of the way you have it (you can't dereference r as it is not a pointer).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't have any experience specific to this area but a search over at IEEE Explore turned up quite a few results. You can read the abstracts and usually find the author's website if something interests you (the articles without a subscription are costly, unfortunately).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have done this in C# but it seems to be a bit different in C++/CLI. I found this page which describes a method but I don't know if it's the most effective.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

On line 11, you're adding the same value (one past the end of the array, not what you want) over and over again. You want to add a[i] . Double check your for loop there too, count the number of elements that loop will step through.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You forgot a 0010 0001 (!)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have a kind of hybrid declaration/definition there on 22 which is incorrect. Change it to look like a method definition without the ; and with (). Of course add any parameters to the method that you need.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If an industry or group or otherwise has a particular parlance you're not likely to find definitions for its words in any dictionary.

I'd say take your "passion" and challenge people on programming language semantics instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you missed my point. Now you have given an entire program in C++. That doesn't help someone with their C problem at all.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do a quick net search for "given an infraction." It's a widely used, do I dare say, idiom. Language revolves around usage. From a practical standpoint, in the scheme of things it probably does not matter one bit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
fstream in(file);

You're in C country :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh trust me if there was such a book, I would have found it by now, lol.

If you're also looking into designing IDEs that you can use with an existing compiler check out http://damieng.com/blog/2007/11/08/dissecting-a-c-application-inside-sharpdevelop -- the book is free and legal.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay, you're still a little off base here. I'm not understanding why you need two functions, openFile and process. I would not read input in one character at a time. I would use fin.getline() to get the whole line and then process the string "in place". You'd need to step through the string because toupper only works on one character at a time. I would forgo the openFile function. Create one ifstream (still not sure why you have 2 in the process function). Read the string in, process it, and write it out in one fell swoop. That way you don't have to even pass in the fstreams, just create them locally in the function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make a list of string arrays and add them to the list in the order that you add the classes to their combobox. Note in this case that comboBox1 is your classcmbo and comboBox2 is the other one.

List<string[]> strlis;

        public Form1()
        {
            InitializeComponent();
            
            //add your class strings to comboBox1
            strlis = new List<string[]>();
            strlis.Add(ManaUsers);
            strlis.Add(RageUsers);
            strlis.Add(NrgUsers);
            strlis.Add(RPUsers);
//.......
//.....
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox2.Items.Clear();
            foreach(string str in strlis[comboBox1.SelectedIndex])
                comboBox2.Items.Add(str);
        }

EDIT: adatapost beat me to it. You can decide which method works for you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ah, I see you just got the bracket in the wrong place. There is also a comma after int that should not be there. Here it is cleaned up:

//...
    cout << endl;
    }
    return 0;
}

void DivideArray(int table[6][5], int theMatrix[6][5], int, int)  <-----
{ 
  for (int i=0; i < 6; i++) 
      for (int j=0; j < 5; j++) 
         theMatrix[6][5]= table[5][6] / table[6][5]; 
}

Now you should call DivideArray from inside your main function.

Within the definition of DivideArray (it is not necessary for the prototype up top) you need to name those two int parameters (see the line I marked with an arrow) or else there will be an error.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should use a switch statement

char letter;
while (cin>>letter)
  {
    switch (letter)
      {
        case 'd':
        case 'D':
        case 'e':
        case 'E':
         //code here
        break;
       }
   }

There are two different variables in the OP's if statement, your approach will not work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When you are entering a char it's causing the input stream to go bad. I would think clear() would take care of it but I wasn't able to get it to work. There's got to be some other trick to it that I'm not aware of.

The simplest solution is leave your code as it is, but have your user hit EOF (ctrl-z on windows/ctrl-d on *nix) when they are done entering each set of numbers.
Another option would be to take in your values as strings instead of integers and check for "Q". That requires you to parse the strings to get the integers out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you hit the set button and then you hit the calculate button it's going to set bags of feed to 5 (see your button2_click handler). In order for the program to change farmer.NumberOfCows on line 28 of the first file you must move the numeric up/down to a new value and not hit the set button. Otherwise you would undo what you just did.

In terms of the second issue, your Form1 is a class. Just like any other class it can have private variables. On line 14 you are declaring a Farmer variable that is a private member. You could, as far as I can tell, have combined lines 14 and 18 and left it where line 14 is (as Farmer farmer = new Farmer() {NumberOfCows = 15}; ). However, if you eliminated line 14 and tried to move the whole construct ( Farmer farmer = new Farmer() {NumberOfCows = 15}; )to line 18 farmer would be local to the Form1() constructor and invisible to the other methods which need to access it. The way you have it now allows the greatest flexibility and makes sure the farmer object is initialized only when Form1 is created.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put in a cin.get(); at the end of your code, before your return statement in main().
If the get() is being falsely triggered by an excess character in the stream, put in a cin.ignore() before the call to get().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A quick hint. In the function that starts on line 38 you create one file stream, then create another, only open a file in the second one and then try to write to the first one. It's ok to be frustrated but take a step back and ask if what you are doing makes sense. You do the same thing with the infile/fin in the function starting on line 22. Open one stream and do what you need to do with it.

Your function on line 50 does absolutely nothing. If you're going to close the file streams (and you should), close them within the function that opened them. If you really wanted to you could pass around references to your infile and outfile but that's a bit tedious.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use a 2D char array to hold the lines. This works best when you know roughly how many lines and how many characters in each line. Then use fgets to read them into the array one by one.