jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not certain what the exact problem with your program is, but Dev-C++ is no longer in development, so the one that you can download will almost certainly have an older version of Mingw (Windows port of gcc/g++). That should mean that some portions of your program should run more readily on the Dev-C++ setup if they are less standards compliant. Since you are seeing the opposite effect, I'm not sure.

I did get some warnings when I compiled it with g++ 3.4.2 (which is about a full version behind but not as far back as the one that comes with Dev) and main should return an int according to the standard.

In function `bool checkBoard(int (*)[50], int, int)':
60: warning: unused variable 'counterD'
103: warning: control reaches end of non-void function
 At global scope:
186: error: ISO C++ forbids declaration of `main' with no type
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

main() is never void, it always returns an int according to the standard.

As to your actual problem, you are mixing up the syntax for printf (the function in the C standard library) with the syntax for cout. Look up the syntax for cout (or find one of countless examples on this site).

Hint: s[0] is the first character of the string s

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Get rid of the 'q' != part and test whether str is equal to q before line 21. If it is, break out of the loop. That's probably the most straightforward way to to do it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why didn't my code run? It runs fine for me. I'm confused.

double SumN(double *array, int size);{

Your function is right in the middle of main(). Unless I'm missing something, but at a minimum your braces are off.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It shouldn't all be crammed into main() like your code example, according to your assignment. Your main() will have your variable declarations and other such housekeeping, but it will be closer to what you put forth in your "Ex".

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use [code] //code here [/code] tags next time (also, really you should have started your own thread even though it's the same class problem)

You misunderstood me, the cout<<i part was just for illustrating the scope issues. Instead, in that loop, call your function on a and output the results.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If your for loop looks like

for (int i = 0;i<size;i++) //the key is the int i portion
{


}

cout<<i; //won't work, i doesn't exist.

the variable i will exist only within the for loop. This is useful if you have multiple for loops and you want to reuse i as a variable in all of them, it would be permitted.

Having

int i;
for (i = 0;i<size;i++)
{

}

cout<<i; //you can access i out here because it is within scope

So your error message is from the compiler saying (I think) that even though it is not declared that way, "i" is being considered local to that for loop like in the first case I showed.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Wow that might be the most non-intellectual question I have read on this forum. You should get a prize or a cookie.

Yes, a prize...

This reminds me of a quote from Office Space that I will quote sarcastically to the OP.
Bob Slydell: "Absolutely, the pleasure's all on this side of the table, trust me..."

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your function does not belong in the middle of main:
Remove lines 15-18

Move line 15 to line 5.

After the close of main (i.e., after the }) start the definition of your function int SumN(int size) (no semicolon in the the function definition)
Enclose the body of the function in braces. Notice that main itself is a function that (in this case) takes no arguments and returns a value.

You're going to need to make some changes in the function also, as you never declared total, you didn't initialize i, and you would end up returning the first value only, as once the function hits that return, its execution is over.

As far as the second issue goes, you never use your function in your code. Call it instead of just spitting back the original set like you do in line 33.

I say this again with your best interest in mind. Run through your textbook to look at the examples at least, and try to emulate their syntax.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Repost your complete code and error messages.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The array notation that SgtMe uses is correct for the body of the function. However, read your assignment carefully in that it wants you to sum from 1 to N for each of the N, rather than sum the array together.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your function does not belong in the middle of main

#include <iostream>
using namespace std;

int SumN(your parameters here); //function prototype

int main()
{


}

int SumN(your parameters here)  //function definition
{


}

Note you can put your function definition where you function prototype is and forgo the prototype. Skim through the section of your book pertaining to functions.

I omitted the parameters, but the ones you had originally were basically correct.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can train a dog to paw the keys on a typewriter, that doesn't mean it can write a novel or care what it's doing for that matter.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Narue has an excellent tutorial that also goes into many of these issues (http://www.eternallyconfuzzled.com/tuts/algorithms/jsw_tut_rand.aspx).

Thanks for pointing out the limitations, Andrew.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use code tags [code] //code goes here [/code].

Your cin statement for name will not work because your patients have a first name and surname separated by a space.

Can you sort an array of integers via a bubble sort? Have a look at that site that I indicated, and make a separate program to try that first. Then, incorporate that program into your main one and use it to sort your array based on the patient number.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Hint: if you don't want to use gdb either grab an IDE that supports it (like code::blocks or Eclipse) or do the poor man's debugger and strategically place some cout statements throughout your code (with labels, so you know where you are) to view intermediate values.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I can't tell if this is all you are looking for (as you posted a boatload of other stuff) but check out http://www.daniweb.com/forums/post9554.html#post9554 and scroll about 1/4 page down and that will tell you how to get a number within a range.

To be implemented by contestant: player.c or player.cpp or player.pas

It's reassuring that someone, somewhere is still using Pascal :)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take a look at something like http://www.sorting-algorithms.com/ to get the gist of the sorting algorithms. Give at least one or two of them a try (with code, we don't provide code, that's your job) and post back. Bubble is probably the most intuitive, so start with that one, swap elements until the smallest is at the end, and then swap until the second smallest is second from the end, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do not copy code, you will not learn from copying(wise words from Jonsca)

I learned bool today while attempting your problem.

There's nothing wrong with learning from her exercises, but there's a sure fire way to prevent an OP from copying the code: don't give it out.

Yes! I figured the array out! Thanks so much for your help, Jonsca

Excellent! I had to attend to other things but great that you got it working.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No, that's not the right thing Lanor. I am perfectly capable of giving the OP a working program for this problem. He/she won't learn anything the way you have done it. (Besides, never use goto)

invisal commented: Sorry... my mouse accidentally click on -1.. Really sorry. +6
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Look at line 4 in your code. Do you want to be taking in input for each element of your array? Doesn't make too much sense. Notice I had input the ID outside of the for loop.

Think about setting the whole thing up in a do/while loop, where the end result is going back to the beginning.

Roughly:

do {
   cout<<"Enter your student ID: ";
   cin >> id; //don't use k for this too

   for (int i = 0;i<n;++i)
   {
       if(StudentID[i] == k)
       {
            //do all your other stuff here using this i
            break; //since you are done with the loop once you've found it
       }

       //else we keep going through the loop
//prompt the user if they want to go around again and use that in the condition
//in the while loop
}while( condition here);

I wouldn't worry about ruining your program hehe. There aren't many among us that haven't scrapped large sections of code from time to time.

See if that gives you some leads. If you have to, take out all of the other calculations and displays for now and start with finding if the ID is in the set, build from there.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't want to find the largest. You have to swap the elements of the array to sort it, what you have only gets you the maximum.

some p-code:

For (over all the elements except the last)
   For(from the one after the last element sorted to the second to last)
       if(this element is less than the one next to it)
           Swap the two (hint, you need a temporary variable) since we want the  
           higher numbers on the left hand side for decending.

If you search for bubble sort on the net there should be sites that have animated examples, maybe one of those will help you visualize it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Regardless of whether or not it is found, your results section is going to output for the current k, so if k=0, you're going to get index 0 from your other arrays.

Some p-code:

Input the ID
For loop (over all the ids)
   If it exists, note the index of it
      Calculate and display that index of the other arrays
      Break out of the for loop
   Else
      Go back to the Input the ID step
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sorry, perhaps I wasn't clear, my fault. Move them out of the for loop and into the main body of the ValidPassword() function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take 62 to 73 out of the loop so they won't display for each character you are checking.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Sort the two arrays in parallel (every move you make on the scores array, make on the names array so they will line up).

Go through a sort by hand and translate those steps involved into a set of loops that will do the same thing. A bubble sort will be the same thing as you would do by hand if you were forced to swap only one element at a time.

A hint, your code on line 60 replaces totals with totals[i+1] but leaves totals[i+1] alone, so there will be 2 copies.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See if using this->Hide() on line 5 gives you the effect that you want. Your first dialog will still be in memory. Unless your dialog has lots of controls on it, this shouldn't be a problem.

I think this has something to do with the fact that the second dialog is an object in the first dialog, so killing the first dialog (I think, it's logical) calls first's destructor which gets rid of the second dialog. I was getting the behavior that they both stay open, so there may be measures against this that are happening behind the scenes.

If this does not answer your question, see what AD can come up with, and if it still doesn't work try it over in C# (specify that you have asked it in C++ already). A slightly different syntax would be involved, but the same overall method that someone suggests should work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Number is equal to -1 on line 6.

Is the statement on line 7 true or false?

What happens if the statement on line 7 is true? What happens if it is false?

(if you can't answer the above questions, reconsult your textbook)

What happens once things reach line 15?

Part of the problem is that you are not dealing with actual code, so there's a lot of extraneous stuff like the end if statements that don't actually occur in this language.

I know you want the answer, but it's best to fight with it a bit so you learn something.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ask yourself these questions...How are you getting repeated numbers without a loop? What makes your program run through a second time? Pretend you are the computer executing your program, write out what the values are at each step.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your program <snip> You should

That means you, not us. But seriously, show us what you have tried, don't just drop off your assignment.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use code tags: [code] //code goes here [/code]

Change dirpath to a std::wstring and in the open operations use dirpath.c_str() instead of dirpath, since you need a C style string (null terminated) in that particular function. Using the c_str() method on the wstring gives you the const wchar_t* I've never used wstring, but give that a shot. I'm not certain if you need an additional header, but since you are using these wide character methods in your code, hopefully you have some idea of that. You definitely need the c_str() one way or the other.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use code tags [code]//code goes here [/code]

In your GetString() function, add a cin.ignore() after the cin.get. There's probably a stray '\n' in the stream which gets picked up by the cin call in the GetNumber() function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm confused by your use of double on the function prototype (which is ok where it is, but is usually placed before main instead of on line 6) and void in the definition. You seem to be expecting it to return a double (again, not sure why you want to output a single value) when you output on line 16. Why is hold a double when all the members of a are integers.

Try making those fixes and then if nothing takes post back. I didn't run your program, so I don't know if your sort works properly.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Oh stop being mean :) Congrats!

Besides, I find it quite amusing that everyone else who commented has WAY more posts ;)

That's like asking a fish to stop swimming. "In my day," we never bragged about getting into the top 100, since there was no such thing. :P

Nick Evan commented: Back in the day we bragged about how many "stars" we had +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

A simple

string surname;
string firsname = record1.takerecord(surname);
cout<<"record1="<<firstname<<" "<<surname<<etc.

There's no need to keep calling the method. I honestly can't remember if the order of execution of the "<<" is guaranteed to go left to right from implementation to implementation, which is why I didn't put it all on one line.

You could also modify your method to keep things less confusing.

void takerecord(string & name, string & surname)
{
    name = name1;
    surname = surname1;
}

Which avoids having to know which is returned and which is passed by reference.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In celebration, I'm going to pour myself a tall glass of "who the hell cares." :D

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@evstevemd - the OP is working with .NET so an unmanaged library like that would require marshaling between the unmanaged and managed layers

@OP - You should be able to use the C# library in your C++/CLI code. The intellisense in 2010 is crappy for C++/CLI but see what happens when you add the C# dll to your project, whether you get access to the namespaces.

You should get the same methods you would use in C#, but you'll have to determine which of the . are namespace related and turn those into :: and which of the . are method/member related and likely turn those into "->" I have never done this but it seems like it should be somewhat straightforward between 2 .NET languages.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Great! I was going to suggest something to that effect, but I had wanted to verify it with your file first.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can't return more than one value. Pass in your second variable by reference: string takerecord(string & surname) { //set surname equal to surname1 and return name1 }

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Which compiler and version are you using?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You never use the i from your for loop in the calculation. You should use that value to calculate the monthlyInterestRate inside of the loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post a couple of lines of your data file? Your code resembles C more than C++ (other than the fact that you included iostream).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Well, that's fine too. I was trying to point out it was a misspelling of the variable name (spelling counts, ya know).

Hint: at this stage of the game, put in a few lines of code, compile them with no errors. Add in a few more lines. Compile again. That way you'll be able to keep track of exactly which line messed things up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, I see what you are saying... How about if you put it within the p for loop, but only set maxDefect[p] = dayDefect[p] if it's the first p in the loop.

Set variance initially to maxDefect[1] - minDefect[1] (if it's the first part again, so you can include this one in your if statement from the first issue above) and use something similar to lines 32 through 35. Don't call the variable on line 36 minVar, call it something like Var and find the minimum of the Var values.

bool myFlag = false; //just a boolean value (true or false) in this case the 
//flag is unset, just expressions from old(er) folks

if (selection < 2)
{
   //Run your menu item 1
   myFlag = true;  //set the flag
}
else if(myFlag) //meaning myFlag == true, since it's already boolean
{
  switch(selection)
  {
      case 2: //etc. etc.

   }
}

You get the idea. I'm sure someone is bound to point out a fancier way of doing it, but trace it through by hand to see that if the flag's not set and the menu selection is something else, it will pass right through the if statements and you can loop around again.

Hopefully that leaves you some fun on your own.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Compare lines 17 and 25: Look carefully at your variable name.

Also, look at line 20: Can you assign an input value to an endl?

On line 25, see what happens when you remove the ==true

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If it's not working to set the initial value inside of your for loop, try it before the for loop. That way it will be assigned for each iteration of the days and not reassigned for each product.

What is the formula you are supposed to use for minVar? I would suspect you would find the mean number of defects and the minimum variance would be the one with the least value for number of errors - mean.

Set a flag (bool value) between your first case statement and the break so it's true once you've run that method. Put an if statement around your switch statement that will only let a selection greater than 1 go through if that flag has been set.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're missing a couple of () but yeah that's the general idea.

To consolidate it further:

if(myStudents[counter] == userChoice) //statement in parens evaluates to true or false
{
     cout<<"Yes,"<<endl;  //etc.
}
else
{
     cout<<"No,"<<endl //etc.
}

Someone is bound to point out that you don't need the braces, but it helps to put them in initially to tell where everything belongs.

So, look at the statement that I made and trace it though to see why it's equivalent to your statements (with a lot less code). Hint, saying anything == true is redundant.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Please use [code] //code goes here [/code] (code tags) to maintain the formatting of your code when you post it.

What are the errors that you are getting?

Try to consolidate your code inside your for loop down to just a couple of lines. Hint: myStudents[counter] == "Andy" resolves to either true or false.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think your assignments are slightly different. The OP had the assignment to input 50 values and output 50 more numbers, each of which was the sum from 1 to N, where N was the original number.

So for the OP if the original array was [2 6 ...] the output is 1+2=3 and 1+2+3+4+5+6=21 etc.

@NU8 Your assignment is to sum the original array of 50 elements together. So, for the same array [2 6 ...] your sum is 2+6+... See if you can tweak your function to do that instead.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you're on the right track with setting minDefect[p] equal to the first dayDefect[p] value, and do the same with the maxDefect[p]. If you were keeping track of this information on paper, you'd write down the dayDefect value for each of the 9 parts, so then your min and max for each of the parts would be equal to that part's dayDefect[p]. New day, new dayDefect[p] values which if they are greater than the old maximum, they are the new maximum, and if they are less than the old minimum they are the new minimum.

Hopefully that's clearer than it seems to be to me hehe.