jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you want to leave setEl intact what you could do is have your methods return an object of type matrix that you create and put your summed values into (same idea for subtraction). That way your counts are right and it might even be a bit cleaner than overwriting.

Otherwise, decouple setEl and the nent counter and have a "shell" method to use from main() that calls setEl and then increments the counter when it's necessary (so in your add method you would call the plain setEl without the counter).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Where do you have the declaration and definition of the first code box above? You most likely need to put the declaration (top line) into your class declaration with the friend keyword in front of it. Then just include the definition in your implementation file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you adjust your function's signature to: void addNames(ifstream& fin, ofstream& fout) (the parameters used in the function body must match those in the signature)
you can avoid the global variables.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change the name of setX to Roll. Add a statement to Roll to set the old value to another private member variable. Make a new setX that has the signature void setX(int value) which is only used to set the value of the die if necessary.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

vc++ is not a compiler, its an IDE. Your compiler is most likely MingW.

No, Visual Studio/VC++ Express has its own compiler. If you are using an IDE such as code::blocks or Dev-C++ that comes with mingw in some cases then that will likely be your compiler.

@OP I'm presuming you mean Visual Studio. This has the capability to do C#/C++/VB/ASP.NET etc. (a couple others in VS 2010). You are still more than likely using the C++

I need to write a class to convert day of the year to the month and day.

Ok so you're talking about the declaration of the class being in a header? It can be. Write out the declaration and see how far you get and we can look it over for you. Remember it's just the the types and access (public, private and protected) of the member variables and member methods(what you might call functions).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I keep getting "program has exited with code 0"

This is referring to value sent back via the "return 0;" at the end of main not to any result in your program. In the past (and probably still currently)people have used different error codes to signify different events causing the program to exit this is why the IDE is reporting this to you.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's just something to keep in mind. No permanent harm done. I would look and see if Qt has any translated manuals anywhere (Google is still your friend in that case). Start simple as Qt is a very complicated system (it has a lot more to offer than just the GUI building aspect) and build your way up.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@tetron
Some additional material for this thread can be found here as well

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What have you tried coding thusfar?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, it's been suggested. The OP hasn't reported back yet.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Gotcha. Hadn't considered that.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

replacing Tile with Tile1

I'm not sure what the OP would gain from that.

I ran it and I got a vector of size 400 at the end of the Area constructor.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

One more observation: When you are adding the matrices together you are calling setEl. Each time this is incrementing nent even though the matrix is already full. So in some form or another you'll have to integrate that count updating in another part of the code.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

When I cleared the parentheses mentioned in the other post (line 35 in this code) I don't get any errors or warnings.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of the problem is this line in getVal: for (j=0;nent--;j++) You don't have a stop condition on the for loop -- I think you wanted j<nent .

Also change the return type of getVal to double since that's the datatype of "data."

This doesn't solve everything but it should get you a little further.

What still bothers me is that you aren't passing any indicies to getVal.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

He means when you declared area_tiles I think it might be the parens you have after t. You don't need them when declaring an object by the default constructor. Just do Tile t;

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I have mingw 3.4.2 (I have a later 4.4 version but there is a quirk in it with the iostreams and -ansi so I put it away for a bit)
I tried compiling:

void main()
{

}
maintest.cpp:2: error: `main' must return `int'

and that was without any switches to make it more strict. It's really just wrong to have it void but that idea took hold in people and then they wrote books. :)

wouldn't that defeat the purpose of private members?

I'm sure there's a "grand scheme" kind of reasoning for it but I do not know it offhand. I'll try looking a little later.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Firstly use int main

...because it's complying with the standard and won't compile on many modern compilers

there is no builtin function for two objects of //the same class to talk to each other

This is not true. It's a bit counterintuitive but objects of the same class can access the private variables of the other.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

the first number after 9 that cannot be divided by 2 and 3, which would be 25

Perhaps I'm missing something but I don't really follow the logic of this statement at all. There are a bunch that cannot be divided by 2 or 3 or both.

If this is something you are interested in there are scores of webpages devoted to theory of primes, etc. Google can point the way.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Up on line 33 initialize it to zero ( int JOG_min_total = 0; ). Trace it out, the first time you're going through the loop you're getting JOG_min_total = JOG_min + (whatever garbage is in this variable at the start). So if you set it to zero you'll get the JOG_min_total = JOG_min the first time through.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Aside from all the rest of the situation you've got semicolons after your for statements. The loops definitely won't run then.

Just my $0.02, sit down away from the PC with your text and study the for loop because you're just going to frustrate yourself at this rate. I'm referring to things like for (triangle = 0 ; symbol = ' '; number++) . The second position there is evaluated as true or false and if it's false the for loop stops (hint: that will never be false).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

(fill in the name of your own output file for outFile)

Was incorrect, my apologies. I had meant to say the name of your output filestream for outFile.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This may sound like a silly question but did you try hitting ALT-Enter while it's running?

I don't know much about the specifics but from what I've seen on here the later the windows version the less it's compatible with the BGI. I don't think the compiler itself will even run on Vista or later.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I don't know how much clearer any of us can make it for you. Go up to the blue background of the code and click on "Help With Code Tags" or click on the dark blue bold announcement on the C++ forum page.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I know you said it's solved but just to clarify for you. Dividing 2 integers gives an integer result (0) which is then assigned to the double. You found the solution already.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try this:

#include <sstream>
string filename;
stringstream ss;
cin >> filename;
ss<<filename<<".dat";
outFile.open(ss.str().c_str());

The first str() gets the string from the string stream and the c_str() you already know.
(fill in the name of your own output file for outFile)

After further consideration I'm not sure why CP's solution would not work. What was the specific error you were getting?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You might have it set up backwards then. Rand() % 2 gives 0 and up to but not including 2. If the value is 1 it gives 'X', which is ok but then it increments giving 2. If the value is 0 it gives 'O', but then it decrements giving -1.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It looks ok. I'm confused as to why you are incrementing and decrementing playerTurn in the branches of the if.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Should be HotDogStand * CartSales = new HotDogStand[numCarts]; . Any time you are using new in C++ the return value is a pointer to that type.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the first case up above it would be rects[i].getWidth() but in the second case you'd have to downcast it like

(go[i] as Rectangle).getWidth()
or 
((Rectangle)go[i]).getWidth()

of course in all of the above cases i is the index for which you are looking.
Also, if you just had a plain old Rectangle object Rectangle myrectangle = new Rectangle(0,0,10,5); you could access it like myrectangle.getWidth() which is close to what you have there but unless the getWidth() member is static you cannot access it without instantiating (using new to make your own object).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I gotcha now. That's all unfamiliar to me, unfortunately. Someone else will certainly know more about this area. I would only suggest tagging the thread with WindowsMobile and the name of your phone to hedge your bets.

EDIT: I hadn't stopped into the C# forum directly so I had missed your new post. See what happens with that one.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@WaltP - I wasn't trying to imply some sort of disdain for the text-based system but instead was just trying to understand what the OP's intent was. What language were you doing when you used it?

@OP - There was a great thread a couple weeks back about next steps to take in C/C++. It's probably worth a read.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edit up above too. Glad it worked.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change line 29 to:

if(i !=num) 
    cout << "(" << num-i << ")" << "";

Or better you could set factorial to num in your function and change your loop to go from for(i = num-1;i>=1;i--) and only display i.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

C, C++ or Java only

Are you talking about writing something like a console application? Otherwise neither standard C nor standard C++ has any kind of GUI functionality built in. I'm not sure about Java.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

just know Eclipse for Java

Did you do any designing with it in Java (I honestly don't know if does but suspect that among the 10^23 add-ons for it there must be some GUI building there somewhere)? If you just meant you used it as an IDE that's not really what I meant.

Well, do some random googling on the terms that I gave you before and see if anything sparks your interest. The third party libs are freely available (Qt has varying licenses depending on the end product) but you'll need a full version of Visual Studio to use MFC. Win32 and .NET stuff is available through the express edition.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

it won't work without the internet on my laptop!

I'm not sure I follow... how would it work without the internet?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm assuming you're doing this for Windows? Have you had any experience with any of the GUI toolkits? I could rattle them off but there's probably a list on the site somewhere. Ok some examples anyway: MFC, .NET/Winforms (C++/CLI), Win32 API, third party ones like wxWidgets, Qt, you name it. Doing it in C limits those options down quite a bit but it's still probably doable.

I know you probably want to build you own but there's supposedly a MSDN sample project for VC++ 2008 included in this package.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's almost apples and oranges but not quite. Say you have a class A and you put the declaration for that class into it's own header file,one that you wrote. Say that your class B header file, B.h, includes A's header, A.h. If you then include A.h and B.h in main.cpp you will have 2 copies of A.h being included. Your guard prevents this and it's only included once. It doesn't seem like a complicated situation but with a large project there can be crossovers all over the place.

In the case of the headers that we normally include for library files (like iostream) they have their own guards in place to prevent this.

#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1

#pragma GCC system_header

is in the <iostream> header. I'm not sure if this particular pragma is involved in that whole process or not.

If you work with Visual Studio (and possibly other compilers) they also use the #pragma once directive to accomplish the same task.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's a guard against including the information in the header file more than once(which can cause a mess with redeclarations etc.).
You'd put the contents of your header between lines 2 and 3. At first pass if this symbol Test_h is not defined, processing goes to line 2 which defines Test_h and then continues with the rest of the header until the endif.
If you include this file again somewhere and that symbol is found to be already defined the preprocessor hits line 1 and skips to line 3 since the ifndef is false.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
gcc PerfectCalculator.c -o PerfectCalculator -ansi -Wall -pedantic
PerfectCalculator.c: In function `main':
PerfectCalculator.c:13: warning: unused variable `myChar'
PerfectCalculator.c: In function `PerfectCalculator':
PerfectCalculator.c:34: warning: ISO C90 forbids variable-size array `factor'

So the way you have it doesn't compile under standard C. That was more my point. It comes up as a warning but to ensure portability (i.e., your compiler was able to put it through due to an extension) you should probably avoid constructs like that.

But back to the errors you are getting. I'm confused as to where the -1 is coming from? Is that the "value" of array[g+1] because that's two positions too far over the boundary of the array(array[g-1] is the last existing member).

I excluded dividing the number by one

You can fix that by initializing your sum to one on line 38 that way that factor always accounted for. It seems to work for 28 when I run it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The while loops in your functions are definitely not fine. They are locking your program up. You need to re-evaluate your strategy for rounding (see my last post). Your main while loop might be ok but you should still combine those two while loops in main() into one.

I'm honestly not sure how fgets would work with the redirect. I assume it would work fine. You should ask your instructor about it because that fgets/sscanf is a powerful combo. See how the scanf works for you but check it's return value it should be equal to the number of items "scanned" (so in your case would be 2 for each line).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's not skipping anything for me. However it is reading back in garbage when I try to edit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

No prob. It often is like that so no worries.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Non-dynamic arrays must have their sizes known as the file is compiling. That is there must be a "compile time constant" value for the size (I don't believe it can even be a const int declared earlier in the program, but I may be wrong about that) is either:

arraytype arrayname[10];

or you can 

#define MAX_SIZE 10
and have 
arraytype arrayname[MAX_SIZE];

Otherwise you need to declare the memory dynamically using a function like malloc which will give you a pointer to a block of memory.

Anyway, post the code and I'll give it a shot. You don't seem not knowledgeable, I'm not impatient. I just want to make sure I understand the problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't actually return anything from Init(), make it void.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's because array indexes must be known at compile time (unless you are using malloc to create dynamic memory). Try putting it in as a constant value. I'm not sure what was giving you -1 but it's a good bet it is a compiler extension as that should have given an error.

By the way, how are you using bool in C. Do you have a library?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post your code? (or a representative snippet from it)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All you've done there is put the names into a string array. I think what you mean is if you had the class Rectangle, you could create an array of rectangles by saying

Rectangle [] rects = new Rectangle[5];
rects[0] = new Rectangle(10,10,1,1);
rects[1] = new Rectangle(5,5,1,1);
etc.

(just made up a constructor signature there)


Now if all your classes derive from GeometricObject you can create an array of GeometricObjects and store any of the derived shapes in there.

GeometricObject [] go = new GeometricObject[7];
go[0] = new Square(10,10):
go[1] = new Triangle(0,0);
etc.

(also made up constructor signatures)

I believe these objects in the container (those derived of the parent class) can be downcasted to access their members but I am not 100% sure when this will work (I have excluded the GeometricObject since they cannot be downcasted safely).

kvprajapati commented: I like your approach. +7
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm not sure about the skipping. I mean I know what's causing it, the mixing of the cins and getlines but you have ignores in place. Try popping in another one right before your "Add" comment block.

I'm not sure what would be causing the failure to read the file back in (are you speaking of the Edit step?). It looks like things get opened and closed properly. Have you looked (in a text editor) at what the file contains? If it outputs correctly you could see if giving it an (artificial) input file works any better.