jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Line 22 should be rad = input*pi/180; (since pi rad = 180 degrees)

(also cos(2*pi) = 1 not 2)

I didn't check your series approximation but see if that fixes it first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See this recent thread of cwarn23. It's got an administrator response on there from Happygeek.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, I didn't regret clicking on that nearly as much as I thought I was going to.

Save up, buy the real stuff, nuff said.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

So, I have to initialize revenuePercentage and moneyDistributed before line 27?

You can (and should) initialize them when they are declared on lines 15 and 16. Do you see what I meant by my other post, though? What I was saying is that if you have tickets less than zero with the way you have it, it will skip over the else and leave those variables unassigned. If you initialize the variables it will take care of that for you. If you wanted to be extra careful you could set them equal to zero with the if statement on line 22 (you'd have to wrap all the statements in braces like you did for the else) but since you're not going to do any computations with negative tickets there's not much use. That's why I recommended wrapping it all in the else (see below).

Also didn't understand the part where you say to change the if/else to a while loop :(. Haven't learned that yet or at least not that I know of. Sorry for the confusion, haven't had a program like this yet... only one causing problems....

Ok then don't worry about the while loop. Extend your else on line 25 to cover everything from 25 to 71. That way if your tickets are less than zero the program control will bypass all of that code and immediately exit when it hits the return (there are other ways to do that but just letting it fall through is …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do I have to put "revenuePercentage = revenuePercentage /100;" before line 27?

No, but look if your tickets sold is less than zero you don't give the user the opportunity to re-enter and control passes over the else leaving revenuePercentage (and moneyDistributed) undefined. It's definitely not assigned before that. Initialize it to zero and change your if/else(line 22/25) to a while loop where the user is reprompted. That way everything is all set and the program won't accept any negative ticket amounts.

Trace through your program with a pencil and paper by hand and see where different conditions change the flow. Also, it very rarely hurts to initialize these variables to a value when they are declared.

Banfa commented: Just for shear persistence in this thread +1
tux4life commented: That pencil-paper approach is superb! I speak from experience :P +8
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you find a path through your code in which revenuePercentage doesn't get assigned a value? Think about what you've corrected so far.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

PI - predefined constant in math.h

I think it's M_PI (although it may be redefined elsewhere).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also, not to be fussy (but I will be anyway) isn't this C++ code?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The math.h functions take an angle in radians. Use the conversion pi radians is to 180 degrees to convert your angles before sending them in.

mrnutty commented: And the one that solves this mystery +5
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

First, another issue at hand.

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

should be

#include <iostream>
#include <fstream>
#include <cstdlib>

The ones with the .h are prestandard C++ headers (and when using stdlib.h from c, use the cstdlib version).

There's a design problem brewing here. If you are going to have a student as an object, the print method should know how to print the information for that particular object. One object should not be responsible for printing the entire array of objects out.

So keep line 23 as it is, without the array. Change line 54 to have no parameters (since the object has access to its own member variables) and change 57 to output the single student. Instead of line 95, iterate through the array and invoke the print method for each of the objects within.

Also, use this->mark instead of student::mark (and change all the others using ::)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if(values == 00) This will not work as written. Values is an integer variable and I believe this will simply register as 0. You'll have to use another sentinel value or take in input as a string and convert it to int.

Also, your function returns void so attempting to use it with << is causing a problem. You need to output the old array before the function call and then print out the new version of a that has been changed by pointer.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you're trying to change line 34, bear in mind that you do not set a value for bonusContributed until line 38. There's a linear flow of control, if something is not set, it has no value (or it has whatever junk was in memory at the location where the variable was created). Move line 34 to line 57 and everything should be ok.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not going to look at it until you put code tags (you may have to paste it in again to keep the formatting). And you still have the commas in with the numbers, are you even compiling this at all?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

One quick question: how did you get this to compile with the commas in the numbers? I totally missed that before and even copied and pasted them into the post that I made.

Are you assuming that because you have the if statements on the bottom it will somehow fill in the bonusContributed in the cout statement above? You should really have your if statements before the line cout << fixed << showpoint << setprecision(2);

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was thinking of creating my own rival search engine and calling it "Crosby" ;)

I would see your unrelated Crosby entity and raise you Stills and Nash (and maybe even Young).

I keep wondering when Bing is going to start making decisions for me -- it's supposed to tell me which airline flights are bearing north by northeast while serving pretzels from a flight attendant named Gertrude. And how about that Wolfram Alpha...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok. Glad you got it working. As long as you know what a value of zero signifies you can always leave the declaration at the beginning and check for a zero value at the end. It depends on how careful you want/need to be. I just wanted you to see more why the compiler was complaining about it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I will have to use the dictionary for that.

I use half of mine to prop up the table and the other half to give me a boost while driving. It's a biiig book.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

At no point do you enter the bonusContributed. It might happen to equal zero if your compiler initialized it to that during debugging since you output the value before it was assigned anyway.

n if What would I have to put iI want it to refer back to the "if" and "else" list?

I really have no idea what you were asking there, sorry.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

ah ok. Yeah, looking back I see what you mean now, the way I read it was you had a single integer digit and were trying to "cast" it to it's character. Apologies then. At least you figured it out.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make sure it's between 0 and 9 and then add '0' to it. char a; a= '0' + 1 (a = '1')

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You pick out the random number between 0 and wordCount (exclusive) (which is c on line 80 above, but you don't need the +1) and you return the word at that index back to main (so words[c]). In main you then use the length of that word to get the number of letters.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Either set double bonusContributed = 0 on line 9 (which is probably the quickest) or

if (ticketsSold >= 10,000)
{
     if (ticketsSold >= 100,000)
       bonusContributed = 25,000;
     else if (ticketsSold >= 50,000)
       bonusContributed = 15,000;
     else if (ticketsSold >= 25,000)
       bonusContributed = 8,000;
     else if (ticketsSold >= 10,000)
        bonusContributed = 3,000;
      ELSE
         bonusContributed = 0 //or another appropriate value
} //even though you've accounted for all the options the compiler thinks
 // that something could sneak through without the else condition

ELSE
{
     bonusContributed = 0; //or another value
}
//same here, if your value is 9999 then what is bonusContributed
//with the way you had the code previously?

That way any path you take through that code, bonusContributed will be set equal to zero.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can set it up however you see fit, I was just observing that you were reading them all in and then when you needed one, reading it in from the file again.

Getting the number of characters in a std::string is as simple as myString.length() , getline reads up to the newline character so unless you have multiple words per line then it should give you exactly what you need.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're doing a couple of things that are confusing to me.
When you're getting a random word, you're reading your file back in again. You already have the words in the array, you should pick a random one out of there.
You also don't use the return from randomword at all. You should read this into a string and use the .length() method of the string to get the number of letters.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Next time please use the code tags. Type:

[code]

//code goes here

[/code]

Since you assign bonusContributed a value in an if/else structure, if your sales are less than 10,000 you won't assign it a value at all. Even if it is >=10000, your if/else if statements in the second tier have no "else" clause so there's some chance (at least conceptually, to the compiler) that your variable won't be assigned at all.

A solution is to either initialize it to zero (or another value) when you declare it or put else clauses with both the if(ticketsSold >=10000) and the if(ticketsSold >=100000) .

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I like The Big Bong Theory right at the moment.

Sheldon is so geek!^^

Is that a different show than the one on CBS? ;) [isarcasm] Careful, material like that is going to mess up your sig link hits. [/isarcasm]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know that there is any problem per se. You have something which is requiring a lot more iterations as the file increases in size (but I don't know to what degree). This gets into issues of complexity but I don't have a good lecture prepared and there are countless others on here that know more than me about that subject.

At any rate, it took me about 26 seconds to process a 164 kb file and 260 seconds to process a 452 kb file and what seemed like 15+ minutes to get part of the way through a 982 kb file. So, it's doing what it needs to do (from a functional standpoint I'm not sure what you are trying to do so I can't comment on that) just very slowly. Use a System.Diagnostics.Stopwatch (easy to use with Start() Stop() and ElapsedMilliseconds() methods) to get an idea of the timing and print out a star every 1000 characters or so to let you know it's still going.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

i want textbox to show all the values i.e. as the values are generated by generate_data class, the values should be passed to textbox in new line instead of overriding.

Or change line 26 to textBox1.Text +=value;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All you probably need is DateTime::Now.ToString() to get the current time and date. I'm not sure why you would need the picker but if you want the user to specify the date you could get it by dateTimePicker1->Value.ToString() EDIT: Was typing during FBody's post but what he says is true. Learn to use the tags or else no more help on your posts.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Okay. Now can you output that line to the screen?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Thanks for the advice. The curious thing about my code is that it works fine if the string is short like "this is a beautiful day", but not for a large text file. Maybe I'll rewrite the code to see what happen.
Btw, what do u mean by data.ToUpper() only changes the string itself?

You could try larger and larger sections to see when it fails. Are you using a console program or a WindowsForms one? (it shouldn't matter but there's got to be some reason behind it).

When you had written that nothing had displayed on the screen I was puzzled because you didn't have any code writing anything to it, so I had thought that maybe you assumed ToUpper was going to display or something...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

IMO, Head First C# is a good way to get from the ground to the first/second floor quickly. From there you could select something more suited to a specific area where you want to end up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Put a breakpoint in at line 5 (above) and check the value of data. It's not echoing anything because you don't output anything (data.ToUpper() only changes the string itself).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're probably a lot more likely to get the help you need someplace like http://forums.ni.com/ni/ (not to say you can't post it here, but just a friendly suggestion)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What do you mean by fails to execute? What do you end up with in the string? Does it throw an exception?

EDIT: I just tested it with 3 copies of a (short) novel in a row (~500K) and had no problem

ddanbe commented: Congratulations with your nomination! :) +6
kvprajapati commented: Congratulations!!! +9
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

C# language ,,this is CPP forum

Meet C++/CLI. We keep it out in the woodshed but it's a member of the family nonetheless. :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Add a constructor to your class:

class DataBase
{
     OleDbConnection MyCon1;
     OleDbCommand MyCmd1;
     OleDbDataAdapter MyDataAdapter1;
     DataTable MyDataTable;

     System.Windows.Forms.TextBox textBox;

     public DataBase(System.Windows.Forms.TextBox textBox)
     {
              this.textBox = textBox;
      }

      //rest of your class
}

(obviously a using directive will eliminate the System.Windows.Forms, but it is not on there by default for a new class)

Then, for a textbox "tb1" in the main form:

private void btnConnect_Click(object sender, EventArgs e)
{
    DataBase db = new DataBase(tb1);
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm trying to step you through the process, since you do not seem to understand the code that you pasted into post #15.

Try to write a program (it's only going to be one more line than the one that you already have there) that reads in the first line of the file (using the getline method to which I have linked).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I understand what your saying but I'm having trouble putting it to my code. I thought I was setting it to first on the list when i coded min = scores[x]. Should i do the same with double min?

How is the min = scores[x]; code on line 42 ever reached if 0 is less than every element? scores[x] < min will always be false in that case when scores are all positive. When you initialize min, set it to the first element (i.e., scores[0]).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you start out with min = 0, and say your list of scores was 90,93,100. Is 0 < 90, yes, minimum is still 0. Is 0 < 93, yes, minimum is still 0. Is 0<100, yes, minimum at the end is 0.

If you start out with min = first on the list when the list is 85 70 94, so min = 85. Is 85 < 70, No, so min = 70. Is 70 < 94, Yes, so minimum at the end = 70.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you are initializing min to zero then it's always going to be lower than any (positive) number that you encounter in the list. Set minimum initially to the first element of the list (works when you're finding max too).

EDIT: Beaten by vmanes. Curses, foiled again!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

1 question: why do you take away 65? Sorry for asking this but I am just a beginner programmer

The ASCII code (see: http://web.cs.mun.ca/~michael/c/ascii-table.html) for uppercase A is 65. In order to translate your char into the appropriate index number you need to subtract that. So if your character is 'B' which has the code 66 and you subtract 'A' you'll get 1, for 'C'-'A' you'll get 2, etc.

I didn't quite get what you were asking about LOTR in the post before your last one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have to include <windows.h> and change a couple of compiler settings to get it to work with the unmanaged code. See http://social.msdn.microsoft.com/Forums/en-GB/vcgeneral/thread/4d24375c-15c5-4c31-ac39-304750a1e556

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, there is an overload which takes a char.

A good reference:http://www.cplusplus.com/reference/string/string/find/

EDIT: AD's got it ^^^^^^^^^ (but that site is still a good reference)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

How about when copying one object of XYZ to another? By default objects are copied member to member. You might need to add something to change this.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post the code, it sounds like you plunked in an unnecessary prototype again.

Or not, but it was a decent guess...

Ok. Well, there's been discussion of atod but I find no such function out there (I may be ignorant of some bit of C lore here). atof should do the job for you (from cplusplus.com "On success, the function returns the converted floating point number as a double value.")

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The best thing to do is go through and check all of your braces again, even if you don't think that's what it is. Go to the Tools menu/Options/Text Editor and turn on "Automatic Delimiter Highlighting". After that go to the end of your file and clear out all the closing } and put them back in one by one and you should get the highlight when they match an opening one up above.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
srand(time(NULL)); //seed
int lino = rand();    //rand number

To use these functions you must #include <cstdlib>

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post the code, it sounds like you plunked in an unnecessary prototype again.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you mean something like:

char a, b;
//read in a and b and change to caps
int[,] occurrences = new int[26, 26];
Console.WriteLine("The Co-occurrence of " + a + " and " + b + " is " + occurrences[a - 'A', b - 'A']);