jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just start j off at i+1. That way you're comparing 0 with all the rest, 1 with from 2 onwards, etc., etc.
If you need to keep track of whether or not you find a birthday more than twice keep the values in an array and check your new entry versus what you already have.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I thought that was the end index, not the length of the substring.

No worries. It's this kind of "gotcha" that can be the most frustrating because it goes unchecked.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Very nice job with the examples. One thing though...

main should always return an int, not be void.

Why? It compiles to valid code, The extra return 0 is just more code to maintain.

Nope. It's non-standard.
Check out this article. Many compilers will not even compile with it these days. As far as your argument goes, even if you don't explicitly include the return 0; it is implied.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I imagine if you followed the if block of the do/while you could get all of the directories and just save the names instead of totaling the file sizes

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

main should always return an int, not be void.
You need to make x and y reference variables, otherwise you're passing them in and they are changed but this is not reflected in the original variables. void A(Complex a,double & x,double & y)

sleepybug commented: yup..the reference thing worked.;) +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Salem
The vice principal who would buy you beer on the side that you never had. Cares very deeply about the quality of the site, keeps people honest, extremely well versed in the C/C++ family (I've caught him in C# before too), offbeat sense of humor. I'm pretty sure he's British but nobody's perfect. Oh yeah and he operates invisibly so sometimes all you will see is the quick drying orange spraypaint in the rep box if you're not careful :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out AD's code snippet it's about file sizes but the code to traverse the directories should be along the lines of what you want. All else fails, google it again.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if (inputStrings[i].Substring(0, 2) == "###") Take a look at the definition of substring and you'll see why this is impossible. I missed it before...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, well you have to get some more info on functions from somewhere. There are probably thousands of sites that cover them online, pick one you like and go through it. But for now...

You know that functions require a declaration (also known as a prototype) a.k.a. the thing at the top of the code with a semicolon after it. A declaration lets the compiler know that "hey, there's a function out there somewhere that takes this number and type of parameters." When you see that code has a header file (usually for accessing a library) it will usually contain these prototypes among other things.

To go along with the prototype your function needs a definition. This is normally found after the closing brace of main() but it's legal to just define your functions before main() and you can skip the prototyping. We'll assume the former for now. So the definition tells the compiler what the function does what it returns and it spells out all the code necessary.
The difficulty you were having was you didn't put any function definitions in your code. You had the prototypes correct at the top but there were no actual functions to go along with them. The compiler was giving you the benefit of the doubt that maybe they were in another file but when it came time to link all the binaries together they were nowhere.

A quick example:

#include <stdio.h>

int addone(int myvar); //your prototype 
                                   //could …
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I made the following changes to the TriviaQuestion class, see if substituting this one in helps:

public class TriviaQuestion
    {
        private string question;
        private string answerA;
        private string answerB;
        private string answerC;
        private string answerD;
        private string correctAnswer;

         //properties
        public string Question { get { return question; } set { question = value; } }
        public string AnswerA { get { return answerA; } set { answerA = value; } }
        public string AnswerB { get { return answerB; } set { answerB = value; } }
        public string AnswerC { get { return answerC; } set { answerC = value; } }
        public string AnswerD { get { return answerD; } set { answerD = value; } }
        public string CorrectAnswer { get { return correctAnswer; } set { correctAnswer = value; } }
 //explicitly tell it to get and set the private member variables
    }

You have it trying to pull data out of answerA, etc. when all your getters and setters (the default ones) are capable of is getting and setting the properties like AnswerA, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm in the process of recreating your form.
Are answerA thru D radio buttons?
What is wrongNotif?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Glad it did!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Have you run it through the debugger?** That will be able to tell you exactly where you lost the data. Otherwise I'll take a closer look.

I'd make a private method for lines 24-31 (Quizform) and call it in the load method and in nextbtn_click.

In Triviagame from lines 33-44. What I would do is read the values into a temp, check if it's got # as the first character, if it does take the substring from 3 to the end and put that into the correct answer slot and where it belongs (a,b,c,d). Just a suggestion. That way you don't have to loop twice.

**if you hate the debugger, which you shouldn't :) but if so pepper your code with System.Diagnostics.Debug.WriteLine() statements and it will show up in the output window of the IDE (or output them to a temporary textbox on your form itself)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

And what is the problem with it exactly?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Add 1.0/1.0+1.0/2.0+... when you do integer division (e.g., 1/2) regardless of the variable the result is going into it still still gets truncated. If you haven't already make sure your result is declared as type double otherwise nothing will work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your method fireQuestion is inherited (publicly) from the base class so you don't need to redeclare it on line 96, it's already a part of your methods in the derived class.
In order to call it you need aColstudent->fireQuestion(mystring,20,0.5,10,20); anytime after line 129 (I have no clue what your parameters mean so I just made up some numbers to fit).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out the third post of this thread. It may hold a solution for you.
I tried the ios_base::in | ios_base::out | ios_base::app approach and the compiler did not complain but it does not seem to work either (which is what is discussed for the rest of that thread -- but I don't know if it still works on the Microsoft compilers today as they were speaking of VC++ 6).
So basically the thread was suggesting if it doesn't open, open one with out only, close that one and reopen it (presumably you can open for in and out at that point).
Hope this is what you were looking for -- there may be a more straightforward solution but I don't know one offhand.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Welcome. What have you written so far? If you haven't started writing what do you have for information on the dates of the divisions?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post more of your class and perhaps a few lines of your text file?
It's not readily apparent (at least not to me anyway) what the problem is from the bit you posted.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There is no null character at the end of a C# string.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I defined the GetInput by tellign it to open the measured_data_t file like I did in my earlier program.

Ok, but do you have it defined in that external file someplace? If so you'll have to compile this file a link with the compiled version of that file (or just compile them both at once). Otherwise the definitions (like what Narue wrote out) will have to be in this file after main().

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to #include <ctime> (it might have to go in as #include <time.h> because VC++ 6 uses some of the old headers). Forgot that in the other post.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is a good site overall to get this kind of information:
http://www.cplusplus.com/reference/string/string/

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out this thread. It's not exactly what you want but it gives some good ideas of how to roll your own.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure who the founder is but she's associated with it (and written the tutorials) for sure. I was being informal.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Place it inside of main()

int main()
{
   srand( time(0) );

A seed is a starting point in the internal sequence for a pseudo-random number generator. Giving the same seed twice would result in the same sequence of numbers.

For more info, check out the tutorial on Narue's website. It's infinitely more comprehensive than anything I could come up with off the top of my head here.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if(name==s[0-4])   <-------??
{
    string name="******";
}

Creative syntax? How about a for loop:

for (int i = 0;i<4;i++)
{
     if(name == s[i])
           name = "**********";
}

if you pass in name by reference you will get the change otherwise how is your new name going to change in main()

for(x=0; x<1;)

You're essentially running through this loop once. Why even have it?

EDIT: vmanes reigns supreme on this one

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where are the function definitions? The compiler is just telling you there's no definitions for the functions at the linker stage.

Also, main() should always return an int.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No biggie. Wasn't trying to be a stickler I just know that often the next post after it could have been "can't find it."

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If element of A is proper

What is your definition of a "proper" element?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

a good one is the mesner twister

It's called the Mersenne Twister.

Just a quick note on the cast in my srand call -- srand ideally takes an unsigned int but time comes back with a one that is of type time_t, which is normally a typedef of integer. srand() may generate a warning otherwise.

NathanOliver commented: thanks for the corrction +1
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

#include <ctime> Then anytime before you use rand put this statement into your program once: srand((unsigned)time(0)); This gives rand a seed based on the current time.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What I had also meant to say (I ran out of edit time) was the the others have explained it very well but this is just my 0.02.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The key to this situation is that even when you are not using getchar within a loop the extra '\n' is still in the input stream.
Since you are not accessing the stream again it just becomes a distant "memory" as your program finishes.
Compare that to when you are going through the loop for the nth time the '\n' character is still hanging around and gets read in.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's in the System.Net namespace. Apologies for the omission.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If blocks is an int array, can't you just change line 8 to: readLevel >>blocks[rows][cols]; As long as your files are laid out in a logical manner e.g.,

0 1 2 3 
4 5 6 7

it should work

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was able to read "COMPLETE" through the following:

string fileline;
     HttpWebRequest reqFP = 
      (HttpWebRequest) HttpWebRequest.Create("http://jamesgeddes.com/wttr.txt");
     HttpWebResponse rspFP =  (HttpWebResponse)reqFP.GetResponse();
     Stream st = rspFP.GetResponseStream();
     using (StreamReader sr = new StreamReader(st))
     {
           fileline = sr.ReadLine();
     }
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You have a series of if/else if statements where those variables are assigned with no else statement at the end. What happens if the system goes through those choices and your value doesn't fit any of the criteria -- the variable goes unassigned. So either make your last else if in the series into an else (which will catch anything that doesn't match) or come up with something to put into the variable in the else statment. So for example:

if (numpay == 1)
{
   numpayadd = 0.02 * cc;
}
else if (numpay == 2)
{
   numpayadd = 0.06 * cc;
}
    [COLOR="Green"]else [/COLOR]
{
   numpayadd = cc * 0.08;
}

or

if (numpay == 1)
{
    numpayadd = 0.02 * cc;
}
else if (numpay == 2)
{
    numpayadd = 0.06 * cc;
}
else if (numpay == 3)
{
    numpayadd = cc * 0.08;
}
[b]else
{
      numpayadd = -999;
} [/b]

The only problem with the second one is you'd have to check for that error in subsequent calculations.

Also, please learn to use code tags:

[code]

//code goes here

[/code]
as they maintain the spacing so code is a lot easier to read. Also, for next time try to pare down your code a bit so that people can find what they are looking for.

ddanbe commented: Bravo, for reading 2500 lines of code! +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Modify the constructor of Form2 to take a reference variable of myCode's type, pass it in when you instantiate form2 in form1.

The not all codepaths return a value just means that, well, there are paths through that method that do not have a return value (like an if, else if that doesn't have a closing else or a return value in a loop).
Search around the forum some because this question gets asked quite frequently.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

but i still cant find....

Results 1 - 10 of about 3,840,000 for breadth-first search

Google awaits. I don't really know much about them at all I was just clarifying his post.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's a typo, he meant breadth-first search.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're in C++ now, friend. It won't work if you compile it as C (I'm not up on language extensions and C99 at all but I still don't believe so).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The for loop on line 55 is actually correct (I think the other poster misread it, it took me a couple of times too). It's legal it just seems a little unorthodox, IMO and definitely hard to read. You don't define the function that it calls yet either. You'd written what looks like a prototype and stopped, at least put the braces in and a "dummy" return value or a message to yourself that you need to implement it.

Line 47 is still wrong. What the other poster was trying to get you to do was look up any function with no arguments. You still need the () after the name for valid syntax.

Keep on trucking. It's much improved. Try not to emulate the other code so much that you're not thinking about what you need to do.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Are you allowed to pass anything into ReadQuestion? somehow you have to send the streamreader object in so it can maintain the position in the file each time.

Also, there's no way to access the private question variable in the TriviaQuestion class.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'll definitely file that info away, thanks for posting it back.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if(user=="rahul"&&pass="12345") will only work with std::string not a char array. Look into strcmp is you are going to do char arrays. Otherwise sounds ok. You might have a function that prints out common menu choices and then add on specialized choices for each user.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't think you really need structs for this. If you've covered arrays, strings, and string functions like strcmp and strcpy you should be all set. Rather than keeping a count with the item, keep a count in an int array (match up the indexes with those of your strings),

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I've planned total project in my mind

Ok, if so then how are you going to handle the file handling?
Unfortunately when someone says that they usually mean they haven't thought it all the way through.

have no idea about how Login and Password things are done

Have you done anything with comparing strings? Compare the login to your known logins and the password to the known password for that login.

Here's an article on files. Searching on the appropriate terms will get you more tutorials.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Welcome. Give this a read:http://www.daniweb.com/forums/announcement8-2.html . At least make some attempt at what you have set out to do. I'm confident that you have used files and strings (which is really all the login system is) in smaller programs it's just a matter of making something that can integrate into a project.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Right and then do the transition I was talking about

fib = fib1 + fib2;
fib1 = fib2;  (My other statement was incorrect)
fib2 = fib;
(output fib)

Go through it a couple of times on paper and see that when you are going through the loops the "old" values stick around for fib1 and fib2. They serve as initial values just like 0 and 1 did.
I'm sure you've done a for loop before and the while just follows from the for loop with a different layout of the same conditions (basically) and then a do while delays testing until the end of the loop.