jaskij 45 Junior Poster in Training

1. The problem you have is gets catches the EOL you get after hitting return for the number of the kids. Adding something like getch() before that gets() should fix this. Or just use gets() twice.

2. Use string instead of string.h - the second one is legacy AFAIK.

3. Don't mix C++ and C I/O. Use istream::getline() or getline() from the string library.

WaltP commented: Terrible suggestion. -4
jaskij 45 Junior Poster in Training

1) Mostly internet and friends, although books help too. Never got myself into reading others code.
2) Interested and challenged.
3) Pascal, due to school, then switched to C++.
4) Some basics of a few languages, but none enough to be useful.

jaskij 45 Junior Poster in Training

For integer division, a/b, you subtract b from a, as along as a>b, counting how many times you did that. The rest is a remainder (a mod b)

jaskij 45 Junior Poster in Training

Didn't you get a makefile with those examples?
Try looking for one and compiling with it, that should work.

Also, looking at the file header, it is an example from 2002, boost might have changed since that time.

jaskij 45 Junior Poster in Training

I'd say inheriting after STL classes is a bad idea, but that may be just my prejudice.
Consider, what would happen if I were to call Swarm::resize() - your swarmSize member would get invalid instantly.

Well, every particle in the swarm will have the same dimension, won't it? It would be easy if you had vector<Particle> as a member, not a parent then. Just store the dimension inside your swarm class, and pass it as a parameter to the constructor.

But right now the implications of inheriting after std::vector are a bit too hard for me to follow.

jaskij 45 Junior Poster in Training
while(input.length()<10)input="0"+input;

same for input2

jaskij 45 Junior Poster in Training

Hi there everyone :)
Recently, I started to feel a strong need to learn a scripting language. The question is which.
Right now I'm pondering between Ruby and Python.
The conditions are that it should be high-level, object or object oriented and not a functional language.
What say you, geeks?

#Just please don't turn this topic into an argument.

jaskij 45 Junior Poster in Training

My bad.

Turns out reversing the loops wasn't such a good idea. It doesn't fix anything, just brakes some more.

The point here is, that if you convert strings to numbers for computation, they should be of the same length. For the program to work properly, you have to add '0' at the beginning of both strings until their length is 10.

jaskij 45 Junior Poster in Training

W7/Cygwin

Notepad++/g++ for smaller aps (such as helping out on the c++ board)

MS Visual Studio 2010 Premium (bless my Uni and MSDNAA) for bigger aps (mainly due to debugger, I don't have the patience to learn or use gdb).

jaskij 45 Junior Poster in Training

@_@ impressive list BitBit

Well: C++
Fairly: Mathematica
Barely: Pascal, HTML, CSS, XML, XSLT, XML schema

Intending to learn a scripting language, pondering between ruby and python.

jaskij 45 Junior Poster in Training

Ok, now I get it.

It was in this function.
Your problem is that you output the numbers reversed. Just change the loops in lines 221 and 224 for

for (int i = 9; i >= 0; i--)

should work.

And really, DO learn debugging - with it I discovered your problem in matter of minutes. Plus, debugging in Visual Studio is IMO pretty intuitive.

jaskij 45 Junior Poster in Training

Sorry, for line ten it should be answer[i] += answer[i] + result[i] + result2[i]; forgot to add the plus after copying.

Didn't your teachers tell you how to debug? Argh...

The place where your mistake lies - that I can't check with just this much code. That is why I asked you to check it yourself, but you say you don't know how.

Either enter your IDE's name in google adding "debugging tutorial" or post the whole code.

jaskij 45 Junior Poster in Training

Nice one, that :)
Your number is 5-digit in binary. Based on that, in each guess, you set one digit of the number to 1, and then output all the possibilities for the other four digits (which are exactly sixteen), if the user answers 'yes' - you leave that digit as 1, if the answer is 'no' - you set that digit to 0.

For example: I fix the second digit, so the list is:
{2, 3, 6, 7, 10, 11, 14, 15, 18, 19, 22, 23, 26, 27, 30, 31}
If the user answers 'yes', I know the number is of the form xxx1x, if 'no' then number is of the form xxx0x.
Repeat for every binary digit.

There's a whole hell of things you can do to optimize such a thing, but I'll write more once I see some code.

jaskij 45 Junior Poster in Training

You are expected to post the code in the first post, but well.
The algo is pretty simple here - remember those multiplication lessons back in elementary school? For a*b you just make a+a addition b times. Similar with division.

jaskij 45 Junior Poster in Training

One error I see is in line 10. it should be answer[i] = answer[i] + result[i] + result2[i]; otherwise the carry-over wont work.

This function seems OK, the problem is most likely with the format of the results - you seem to keep them starting from the highest exponent and omit the leading zeroes.
Try debugging it. Set a breakpoint at the beginning of this function and see what the results look like.

And two tips:
Use pass by reference or pass by pointer here - right now you just unnecessarily copy those arrays.
Make char hex[16] const - this will help the compiler optimize this function.

jaskij 45 Junior Poster in Training

You're welcome :)

jaskij 45 Junior Poster in Training

Another one with ADD here.

Still a CS Uni student.
What I avoid: repetitive tasks.
What I want to do: challenges, things that occupy my mind.
So my job of choice would be with algorithmics and software engineering rather then coding itself.

jaskij 45 Junior Poster in Training

I'd say some dynamic programming, maybe with finding the shortest route or some such.

Everything probably represented as a graph.

jaskij 45 Junior Poster in Training

Might be something VS specific, compiled just fine with g++ even without deleting line 10 ;P
Oh well, -Wall shows some warning, but nothing much.

Also, include cstdlib - you don't provide the header for the system() function. And you don't need that system("pause") anyways, since you don't output anything to the standard output, only to files.

jaskij 45 Junior Poster in Training

No problem ;P

Inside your class:

void RecordAsset(const MaxSDK::AssetManagement::AssetUser& asset){
int a;
}

Sorry for the lack of indentation, wrote it in the forum posting box.

jaskij 45 Junior Poster in Training

For the file - I second pseudorandom21. If you want, you can use a library for XML.

If you want to store the whole thing in the memory - I'd suggest a tree, where every node can have 26 children (one for each alphabet letter) and the node contains the description for a word containing the letters on the way from root to it.
Or a hash table.

Other then that - go through the file, store the positions in the file in a way similar to what I described above, and just read the file from the stored position to the next marker.

jaskij 45 Junior Poster in Training

Just make an empty method or something, should work IMO.

The question here is, how will that work with Max.
Since the arg is a const reference it shouldn't have much of an impact though.

jaskij 45 Junior Poster in Training

@thines01: considering how the compiler interpets it, it should work, but you are 100% correct that this way shouldn't be used.

IMO, just delete line 10.

jaskij 45 Junior Poster in Training

As you can see, you should implement the RecordAsset() method.

Take a look here: http://download.autodesk.com/global/docs/3dsmaxsdk2012/en_us/index.html

No idea what it does though, I suppose this has something to do with 3dsMax's internal management or what...

jaskij 45 Junior Poster in Training

To be honest with you, I'd say it's not a task for C++, rather a computer algebra system - they tend to cope with similar tasks really well.

Anywas, there is next_permutation() in the STL algorithm header, this should help you using what VernonDozier wrote. Just pick a digit to repeat, make an array(or vector) of them, sort it, then iterate through it's permutations using next_permutation() . Still, you have 10*9!=10!=3,628,800 iterations on your hands.

jaskij 45 Junior Poster in Training

Expected something of the kind.

I suppose telling you what the docs say will not help you, but they mention SIGSEGV after getting a null font.

txwooley commented: Thanks for the help. +3
jaskij 45 Junior Poster in Training

That's because of what you did in line 12.
Why?

int feet ; 0

Should be

int feet=0;

In general, all your variable declarations are wrong. While constants are correct.
After fixing all the variable declarations compiled properly using g++ -Wall The final code is like this:

#include <iostream>
#include <cmath>
#include <string>
 
using namespace std;
 
int main()
{
	const double feet_to_inch = 12; // conversion from feet to inches
	const double inch_to_centi = 2.54; // conversion from inches to centimenters
	 
	int feet= 0;
	double inches = 0.0;
	double total_inches = 0.0 ;
	double centimeters = 0.0;
	 
	// Conversion Program to centimeters
	cout << "The quieter you become, the more you will be able to hear";
	 
	// Entered value by user in feet
	cout << "\n Enter in feet" ;
	cin >> feet ;
	 
	// Entered value by user in inches
	cout << "\n Enter in inches" ;
	cin >> inches ;
	 
	//Calculate number of inches
	total_inches = inches + feet * feet_to_inch ;
	 
	// Convert to centimeters
	centimeters = total_inches * inch_to_centi ;
	 
	// Output results
	cout << "/n The Result is :" << centimeters;
	 
	char c;
	cout << "/n Press anything to Exit" ;
	cin >> c;
	 
	return 0;
 
}
seanster138 commented: thank you so much, i learnt something new thanks to you +0
jaskij 45 Junior Poster in Training

Hard to say, but my guess is you don't implement a pure virtual function that is in the class from which you inherit. Could you give a link to docs?

Also, for more extensive error descriptions, just google "Visual Studio error" adding the error you get. Microsoft provides nice descriptions, which sometimes are pretty helpful. Not this time though.

jaskij 45 Junior Poster in Training

What I meant about ImplementCalculations() is that it's declaration can be

void ImplementCalculations();

since you always call it using class members instead. The code can stay the same since the names are the same.

What is that in line 106? Why do you declare a function there?

The thins with ints instead of doubles is, if you have a number like money - which you KNOW will always be rounded to 1/100th, then just multiply all values by 100, and store those as ints - that's the better way to do it. Although you do have to watch out around multiplication and division.

Please allow me to direct you to the cplusplus.com tutorial - it explains classes in a good way, I hope that will help you.

jaskij 45 Junior Poster in Training

You miss a closing quotation mark on line 17, other than that seems fine to me.

WhiZTiM commented: The OP said line 13! and He didn't miss any qoute at line 17. -1
jaskij 45 Junior Poster in Training

What you have there is not a pure virtual function, but just virtual function.
A purely virtual function would be like: CoreExport virtual void EnumAuxFiles(AssetEnumCallback& assetEnum, DWORD flags)=0; .
A simple virtual function means only one thing: it can be re-defined by it's child classes.

There is a good description of this at cplusplus.com, if my explanation wasn't enough.

jaskij 45 Junior Poster in Training

I strongly recommend using SDL_Image and ditching BMP for better formats, like PNG where you can ditch color keying. It is described a few tutos later on LazyFoo.

Although the reference doesn't mention it, I wonder if SDL_Init() shouldn't be called before a call to SDL_DisplayFormat() .

jaskij 45 Junior Poster in Training

The way I see it, you should not change the dirs, just include the files properly.

The #include <> directive includes files from the compilers include path.
The #include "" directive includes files from the local folder.

I hope this clears things up.

jaskij 45 Junior Poster in Training

binaryhash.h line 46 You need a forward declaration of the struct node . Or just move the private part before the public one. binaryhash.h line 46 void deleteNode(node *n) takes a pointer, not a value. binaryhash.h line 54 This one I don't really get, probably some spelling mistake or something.

jaskij 45 Junior Poster in Training

+1 to WaltP

Actually, did you read the error(shouldn't it be a warning?)? It should clearly state the line where this uninitialized variables is used.

Other than that, you never set result inside main()

jaskij 45 Junior Poster in Training

It is probably an error in your implementation, I'm not going to look for the particular cause, just list all the things I find (more or less) wrong in your code.

1. Use vectors!

2. Are you aware, that your swap function does NOTHING? Really. It works on local copies. You need pointers ore references there, like void swap(int& a,int& b) 3. You should not pick a pivot at random. Quicksort works well, if each recurring call takes in half of the numbers. So pivot should be a median

4. The swapping is not well done. The way you do it, it will be [tex]O(n^2)[/tex] if not [tex]O(n^3)[/tex]. So you could as well make a bubble sort.

5. I just noticed there is a pretty good pseudocode (for both copying and in-place algos) on the English Wiki

jaskij 45 Junior Poster in Training

First of all, iterate over those powers, don't just put them in the code.

Putting a number to any given base always used a Greedy Algorithm and that is enough for you too.

The only part, that could get tricky here is computing the modulus for floating point numbers, but here is a decent thread on this topic. It IS a bit better than your solution (imagen numbers like 10e10 mod 10e1 - your way would take hours to compute).

I hope you understand this. If not, try googling a bit, or just ask for clarification.

BTW: haven't I seen a number of threads on this topic in this very forum a few days ago?

BTW2: @lxXTaCoXxl - not really, doubles aren't objects of a class in C++. Remember, C++ is not fully object.

jaskij 45 Junior Poster in Training

My guess is that you don't initialize thouse doubles. Or divide by something incredibly close to zero.
I can't see the DisplayTotals() method called in main, so it's hard to say what's actually wrong.

Also, it's an old story, but since those are fixed point numbers, store them as integers (store the amount of cents, not dollars), not doubles, for the sake of accuracy.

Other than that, why did you write the ImplementCalculations() like this? If you always use the values for the current employee, just use the class members, without passing them as method arguments.

And the totals could be stored as static and updated upon each change - would make your life easier.

For the Addsomethingup() method, wouldn't operator+() or operator+=() be better? Then just put them in a vector and go over it summing up everything. In general, it would be better to us a vector (or an array if you have to) for a set of similar objects instead of just making n variables (the only time I've ever seen things like var35 was in a generated code for a shader).

One last thing: please use proper indentation, that would make reading your code easier.

jaskij 45 Junior Poster in Training

This is a linker error.

The point here is, you are telling the compiler to compile this code as an app, not a library, so it expects int main(), which is nowhere in your code.

If this is a school assignment, just adding int main() somewhere below (which you would do anyway to show that it works) should be sufficient.

Or you can build this as a library. For specific instructions how to do it, google your compiler/IDE adding "building a library" - should help.
If, for example, your IDE is MS Visual Studio, google "Visual Studio buidling a library".

jaskij 45 Junior Poster in Training

there must be a library.
And what I mean is, you run a loop (at limited FPS, not to kill the CPU) and in every loop you check if the key was pressed.
Good tutorial on that is at LazyFoo, but it uses a graphic library (SDL) which IMO would be an overkill here, but why not?

jaskij 45 Junior Poster in Training

As I said, I don't really now those libraries, try googling something like "c++ checking if key is pressed", or adding linux in there.

jaskij 45 Junior Poster in Training

http://www.daniweb.com/software-development/cpp/threads/70096

My favourite is Bruce Eckel's "Thinking in C++" - it's available free online, just google it.

Other than that, use cplusplus.com or, if you're using MS Visual Studio, the MSDN Library might be good for you.

jaskij 45 Junior Poster in Training

You could try std::string::find (http://cplusplus.com/reference/string/string/find/) to find the first closing parenthesis, translate the first part, then go on.
So the code would look more or less like this:

string toTranslate;
getline(cin,toTranslate);
int lastPos=0;
int size=toTranslate.size();
do{
	int pos=toTranslate.find(')',lastPos);
	string current=toTranslate.substr(lastPos,lastPos-pos);
	// translate current here
	lastPos=pos+1;
}while(lastPos!=0)

Please debug it, as I wrote it in notepad without any checking.

jaskij 45 Junior Poster in Training

You need some sort of event handling... Don't really know what libs are used under lin.

jaskij 45 Junior Poster in Training

Despairy, you're probably right with SFML ;P
SDL feels a bit like a 90's library, but still, even making a Space Invaders clone using it taught me a lot.

jaskij 45 Junior Poster in Training

prabh94, you do realise, that a factorial increases very fast?
20!~1.216e17 where the maximum value for int is 32 768. That's too little even for 10!

jaskij 45 Junior Poster in Training

Would it be too rude of me if I wrote google.it ?

http://lazyfoo.net/SDL_tutorials/index.php

BTW, AFAIR LazyFoo assumes basic C++ knwoledge.

jaskij 45 Junior Poster in Training

Anything more specific?

I don't really remember the rules for this part of the board, but isn't it more code-centered?
If no, let me just direct you to the LazyFoo tutorial - it covers some basic concepts for both game making and graphics. At least half my year at CS major used it for our last assignment.

jaskij 45 Junior Poster in Training

rubberman, if I understand you correctly, you say that 0%2 causes an FPE?

jaskij 45 Junior Poster in Training

1. Please don't make such ugly one-liners like lines #14 and #33

2. I don't know, if this helps, but x definitely goes into negatives, which might cause your factorial function to do strange things.

Ancient Dragon commented: yes :) +17