siddhant3s 1,429 Practically a Posting Shark

>>I need the answer as soon as you can
We need your to leave this website as soon as you can.
Or:
Read the forum guidelines ( I usually posts the link along but for you, no mercy)
Read the sticky thread by Narue: Read before posting
Read the Forum announcement by the Administrator.

We are not your slave. Neither are you our employer. We are sitting here to help. Not to accept orders from some Tom Dick and Harry.

WaltP commented: You've taken being a jerk a little too far in this post. +17
Nick Evan commented: Take it easy dude... have some tea and a smoke ;) -3
Salem commented: Works for me :) +30
siddhant3s 1,429 Practically a Posting Shark

You have not written a recursive function.
Loosely speaking, Recursive functions should imply removal of ugly loops. I shall rather guide you in your first function.
You are using while to check an condition rather than if. This is unlikely (and maybe wrong too) by your instructor.
Here is a quick TODO for the first function:

START
* Check if Head is NULL; if it is return some value(preferably  zero) indicating failure of search
* Check if Head-info==key; if it is, return head
if it is not, call search(head->link,key)
END

All the checks are to be made be if's and not while. The idea is not to use loops.

blackhawk9876 commented: thx +2
siddhant3s 1,429 Practically a Posting Shark

>>That is incorrect. The pointer is assigned whatever random value is at that
>>memory location. For example char *ptr; the address of ptr is whatever is at that
>>memory location on the stack (assuming its not a global variable). It is never
>>auto set to NULL by the compiler in either C or C++ languages.

I was just about to point out that to the OP and tux.
This might now confuse OP as Tux said "that explicitly initializing a pointer to 0 is a overhead because it is done by default" which is actually wrong.
The overhead is because you can construct the pointer pointing to a new location by directly by initializing it to the result of a new operation:

//version 1// BAD
int* P;
P=new int;
/
//version 2// Good
int* P= new int;
//This is good as you are saving the overhead of assignment.
//As there is no need of assignment, cause you have initialized the P already

Not to mention, assignment and initialization are two different things

tux4life commented: Everywhere siddhant is looking for confusion :) +3
siddhant3s 1,429 Practically a Posting Shark

>>I'm currently using the new borland so this is a correct syntax after all it's
>>working on my computer, as for the variables i am on writing description for
>>everyone of them.
This is a wakeup bell for all those who are using Old compilers ( like the OP is using Borland's) that C++ has been standardized 13years ago. So there is no concept as "It is working on my implementation so it ought to be right".
This is what cooks me up boiling. Ruthless.
To the OP, Please Read :http://cppdb.blogspot.com/2008/10/why-you-shouldnt-use-you-use-old-c.html
and http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html

These are some link is from Bjarne Stroustup's homepage:
* A Very simple ISO standard program http://www.research.att.com/~bs/bs_faq2.html#simple-program
* About void main http://www.research.att.com/~bs/bs_faq2.html#void-main
and
* This ones about naming variables http://www.research.att.com/~bs/bs_faq2.html#Hungarian

(I am really surprised by the guts of OP. A good man (Mosiac) is giving him advice and he is just too much a snob to accept it)

Salem commented: Fantastic!!!!!! +30
siddhant3s 1,429 Practically a Posting Shark

>>Dear NathanOliver, your code is working perfectly after changing..............
It may be working on your implementation but the code is in a state of undefined behavior.

>>Edit:: Some additional information on if (test != input) as 'input' is a double
>>and 'test' is an integer, 'test' will be implicitly converted to a double to do
>>comparison
This can't get worst. When you know he is doing a float comparison, there is a lot more need to warn him than smiling.
To OP and everyone : Never use float comparison in your programs. It will lead to undefined behavior.
You may want to like to read: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17

tux4life commented: Very interesting :) !!! +3
siddhant3s 1,429 Practically a Posting Shark

curl can handle HTTP GET and HTTP POST
It also support FTP
So if this is all you want to do, I suggest go with cURL. Its more generic than anything.

>>But once i'm startet on network related programming (whats the right term?)
>>i would like to be able to do more than that i guess, so i would rather not do
>>to many shortcuts
Yeah, then move to Asio

siddhant3s 1,429 Practically a Posting Shark

Does anyone know how to write a simple crading system in C++ programming???

Yes I know

tux4life commented: LOL :P Straight and to the point :) +3
siddhant3s 1,429 Practically a Posting Shark

>>would you recommend learning python, and then running the python programs trough c++ (seems clumsy)
No, I don't

>>or using one of the libs you mentioned?
>>any change you know where to find a good tut on the 2 libs?
This is much better. Use the winsock if you intent to write only for windows.

>>It seams to be hard, finding the way around the boost asio header files.
>>Or is it just me?
No, it is not just you. It is a hard fact that Boosts documentations are very breif and true to point. You have to help yourself if your using Asio

Bladtman242 commented: Thank you for your answers, they are very helpfull +1
siddhant3s 1,429 Practically a Posting Shark

Inno Setup is a free installer for Windows programs. I used it my several projects wherein I needed to port my Linux Application to Windows user ( windows user really like this setup.exe)

You will be amazed by its simplicity and power.

siddhant3s 1,429 Practically a Posting Shark

void main is a crime. Always use int main. http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html

if( day=0) will always be true. Use if(day == 0) instead. There is a difference between = and ==. The former is an assignment operator. The later is a logical operator, it evaluates whether the LHS and RHS are equal or not.

I don't know julian system so I cannot help you in logic.
Another advice. Try to use more descriptive names of variables instead of a,m,y.
I cannot interpret what does these variable are created for. Use a bigger name. like current_year, current_month. It will surely need you to type more, but it will clear out your path to become a good programmer.

[edit] I was reading about julian system of date. It turns out that the variable you used a,y,m are standard variables. So sorry to intercept. But my advice should be followed in all the other program you will write.

tux4life commented: Very good !! +3
siddhant3s 1,429 Practically a Posting Shark

You have to first create a data structure. An array or vector of int should be the most correct data structure.
Then ask the user how may value you need to input.
Run a loop and accept all those value in a vector ( or array,) from the user. ( by using cin>>)
Now you will have a vector ( or an array) which contain the sequence.
To find the maximum, assume that the first element of the vector (or array ) is the maximum. (this can be done by defining a variable: max and setting its value to the value of the first element of the vector or array) Now iterate through the whole vector(or array) and check if max<n where n is the i-th element.
If it is, set max to n.

tux4life commented: Very good description of the algorithm :) +3
siddhant3s 1,429 Practically a Posting Shark

>>There are several free compilers, such as Code::Blocks, Dev-C++, and VC++ 2008 Express.
( Note to OP: I am talking to Ancient Dragon, this has got nothing to do with you)
I never knew Code::Blocks and Dev-C++ are compilers!! I thought they were IDEs ;)
Or am I sensing it right?

tux4life commented: Absolutely right :) ! +2
Ancient Dragon commented: good observation :) +36
siddhant3s 1,429 Practically a Posting Shark

>>Btw. in your for loop you don't have to test all the way to x. It is sufficient to test just to the square of x.
He meant the square-root and not the square of x. ( must be a typo)

To the OP,
The suggestion of ddanbe is the most valuable here. Read it thoroughly.
As you told ( and we fully agree) you are beginner in C++. Also, the problem which you are doing is very popular and standard. I would suggest you to look a good code that determines if a number is prime or not and learn from it.
This advice would not be given to one who had not tried. As you did, and are nearly on the right track, you should perhaps study someones code.

Regarding the main() function, why are printing even those number which are not prime? You should check if a number is prime or not ( by using the function you wrote) and print it only if it is prime, else don't

ddanbe commented: Nice posting! +4
siddhant3s 1,429 Practically a Posting Shark

daviddoria, read this http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.5
Perhaps this would convince you if John is not able to.

Salem commented: A link of required reading for all aspiring C++ programmers. +29
tux4life commented: Nice FAQ ! +1
siddhant3s 1,429 Practically a Posting Shark

Didn't your professor told you about 2dim arrays?

const int MAX_LEN=20;//maximum length of eachname
char names[10][MAX_LEN];//create a 2D array to hold 10 names of length 20
int N=10;//
for( int i=0;i<10;i++){
cin.getline(names[i],MAX_LEN);

}

Reference to the function used in above code:
LIne 2:http://www.cplusplus.com/doc/tutorial/ntcs/
Line 5.http://www.cplusplus.com/reference/iostream/istream/getline/

As I know that you are a strict follower of your professor (I know this because of your thread on 'operator confusion'), I guess I should not tell you that standard C++ have a string class which simplifies the above process by million times.
One should always use c++ string rather than the Cstring(the one which is used in the above code) every time.
If you could divert some of your attention on standard c++ rather than following strictly what your professor told you( which is Ancient C++ actually) you could find the following article useful:http://www.bilmuh.gyte.edu.tr/gokturk/introcpp/icpp_strings1.html

jam7cacci commented: gives a good references +3
siddhant3s 1,429 Practically a Posting Shark

Well, I guess the kid is ready to slash the mountain.
You basically want to write your own language.
There is a Bible for Compiler writing which called Dragon Book.
http://en.wikipedia.org/wiki/21st_Century_Compilers
It is a vast book. If you are dedicated to write a language, you should pay a price, i.e. Read the book.

Ancient Dragon commented: Very good information and link :) +36
siddhant3s 1,429 Practically a Posting Shark

To the OP:
Read the vmanes post. It is the most relevant here. Technically, you are correct in defining printGrade as void. But as other pointed, the defination should have been also of a void return type as you function names suggests that it should PRINT a value rather than RETURNing it. So switch to void and change the return statement at last to a print statement( in C++, the cout).

Poor boy!

The boy is less poor than you are, he submitted his code in the code tags at least.

ha ha ha true , learn to read the errors and dig them , that is C++ life.

If you were saying all this to Ancient Dragon, alas you didn't got his point. He was emphasizing that the OP should be specific in what error he is getting. And one should respect the quality posts Ancient delivers.

tux4life commented: Nice post ! +1
siddhant3s 1,429 Practically a Posting Shark

I need the full code of how to do it

You would never get full code here.
Google is your friend. Here is a nice article here on Daniweb about generating Random Numbers:http://www.daniweb.com/forums/thread1769.html

Off-Topic
"Laughter Laughter, Laughing at my cries"

siddhant3s 1,429 Practically a Posting Shark

return 0 is not mandatory when writing C++ main function.
Read Bjarne Stroustrup ( father of C++) homepage: http://www.research.att.com/~bs/bs_faq2.html#void-main
Here is the excerpt from the page:

In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example:

#include<iostream>

	int main()
	{
		std::cout << "This program returns the integer value 0\n";
	}
tux4life commented: Nice to know ! +1
siddhant3s 1,429 Practically a Posting Shark

>>Yeah, it's .c_str()
NO. it is .str() for string streams.It will return a string object on which you will have to do a .c_str(). So the corrected code would be somewhat like this:

#include<iostream>
#include<sstream>
int main()
{
    std::stringstream arg;
    const float pi=3.145745;
    arg<<"AdjustSealevel.exe "<<pi;

    std::cout<<arg.str().c_str();
    system(  arg.str().c_str()  );
}
Comatose commented: Aha, You Are Absolutely Right. Nice Job Man. +12
siddhant3s 1,429 Practically a Posting Shark

If you drop Point #2, Python can be your wand. It is a language which will support easy transformation of your ideas to codes.
If you drop Point #4, C++ satisfies all the above points.

Perl is an interpreted language.


I still would go with python since it is really easy to learn and follow. It is not as fast as most of the compile time languages(like C,C++) but you won't care about speed for most of the matters.(All I meant to say is that it will compete C|C++ in most cases)
Python though requires python runtime requirement. But it is not a bad thing until you are programming stealth tools like trojan horses or keyloggers.

siddhant3s 1,429 Practically a Posting Shark

Look, you are on the right path.
If you have already overloaded the operator= and operator+, you can use them in the definition of operator+= .
Say the parameter of the += operator is aSimpleString.Then, the definition of += operator may look like.

(*this)=(*this)+aSimpleString;
Vallnerik25 commented: He helped me solve my question quickly and with correct and kind suggestions. Awesome poster! +1
siddhant3s 1,429 Practically a Posting Shark

Oh man!! Ancient Dragon would be snatching his hairs!!

Look kavithabaskar, You are basically using recursions to avoid loops.
Every series has Recursive form and a closed form(non-recursive)[Note that it is not possible for every series to have both forms].
Say, the series 1,2,3,4,5,6,7,8 has a recursive form as [TEX]A_{n}=A_{n-1}+1 || A_{1}=1[/TEX]
and open form as [TEX]A_{n}=n[/TEX]
So, if you know the closed form it is best to use it through loops.
But when you dont know closed form you go to recursive functions.

Ancient Dragon commented: LOL +36
siddhant3s 1,429 Practically a Posting Shark

>Don't stop C++ programs with exit() function (except on severy run-time errors).
I fully agree with ArkM.
exit(0) is evil
I would extend ArkM's advice that you should not use exit(0) even in case of runtime errors. You should use exception handling mechanism.
Ideally, All functions, sub routines should end back to main() and main should return something.

siddhant3s 1,429 Practically a Posting Shark

>can someone teach me how to use pointer in this program??i don't know if what i did in this program is correct. can you tell me how to use pointers here.thanks!

Please Be specific.
This is not a teaching classroom dear. You must read your text book and come to us with very specific questions.
We, can tell you how to use pointers but how the hell are we suppose to explain you the whole program. Do you think it is feasible?

Secondly, DO NOT USE VOID MAIN() http://cppdb.blogspot.com/2009/02/should-i-use-void-main-or-int-main-or.html

use #include<iostream> and #include<cstdio> Use a new compiler not a old one(http://cppdb.blogspot.com/2008/10/why-you-shouldnt-use-you-use-old-c.html)

And thirdly, The program contains lot of (trivial) errors. We are not going to debug them for you. For your curiosity, there's a error in the cin>>inputfruits() You cannot cin to function.

So, please correct the errors and read the book. Then asks what is troubling you.

tux4life commented: You're always making good advices !! +1
siddhant3s 1,429 Practically a Posting Shark

If it is a standard header, (like cstdio, iosteram, fstream, string, cmath, cstdio etc.) #include<iostream> instead of #include<iostream.h>

But if your header is non-standard (like gtk.h, sockets.h or myHeader.h) then you should #include<gtk.h> or #include<socket.h>

If the header file is home-made, you should perhaps
#include "myHeader.h" which usually tells the compiler to look for the file in the current directory rather than the standard include directory.

lllllIllIlllI commented: Thanks +1
siddhant3s 1,429 Practically a Posting Shark

Look at line 34 furlong.h (class Kilometer& kilo) You are using Kilometer here. Right? Now just tell me, have you told your compiler before that something called Kilometer exists? No.
So, what to do?
Simple, you need to tell your class furlong that there exists something called Kilometer by declaring it once before the declaration of class furlong. This is called forward declaration.
You just need to put a

class Kilometer;

just before the declaration of furlong class(i.e. line 12 of furlong.h). Something like this:

class Kilometer;
class Furlong{
private:
int furlongs;class Kilometer;
..
..
..
..

For more info about forward declarations:http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.11

CPPRULZ commented: AWESOME +1
siddhant3s 1,429 Practically a Posting Shark

C++ FAQs by Marshal Cline is a good, free resource.
If you are a absolute biginer you must read "The Correct C++ Tutorial" http://home.no.net/dubjai/win32cpptut/html/
Thinking in C++ by Bruce Eckel is a nice book(free online)
You may visit the Sticky forum about C++ books http://www.daniweb.com/forums/thread70096.html

vmanes commented: Good advise for the student +7
siddhant3s 1,429 Practically a Posting Shark

Well, your do-while loop is absolutely fine.
The problem you are suffering is that:
1. You are not initializing the array new_string when you are using it. Add a for(int i=0;i<256;(new_string[i]=0),i++); before the int x = strlen(your_string)-1; in definition of ReverseString().
2. You are not flushing the input stream. Add a cin.ignore(1000,'\n'); after cin>>choice Thats all,
Try not to use global variables. Use the code-tags to post the code.

Mossiah commented: Nice work. thanks very much for your help +1
siddhant3s 1,429 Practically a Posting Shark

Please be specific. No one has time to look at your 1MB code and point out the error.

Salem commented: Quite so! +29
siddhant3s 1,429 Practically a Posting Shark

>Help me!!!! about operator overloading
It doesn't work like this. You should be more specific about what you want to ask.

First of all read this link -> http://www.parashift.com/c++-faq-lite/operator-overloading.html and come back.

BTW a short answer to why we use operator overloading is so that our class have a intuitive interface.
Suppose you are writing a class called Date then you can overload the - operator to give you the difference in days between two dates like

Date d1("5/5/1991");
Date d2("30/5/1991");
cout<<d2-d1;
ddanbe commented: Very good answer to the question at hand. +4
siddhant3s 1,429 Practically a Posting Shark

You have any idea what are you asking?
We don't know you, nor your ability, nor that how much time you have, not how much brains you have. We know nothing of you then how can we tell what is a "mini" project for you.
Mini can be a Hello World program or mini can be a writing a C compiler.

Salem commented: I agree +29
siddhant3s 1,429 Practically a Posting Shark

Are you done? I still am seeing the thread as unsolved.
Solved link is near the bottom of the page

00Vic commented: I found his posts helpful for learning new concepts +1
siddhant3s 1,429 Practically a Posting Shark

Hope this helps...

Yeah, it will surely help him. He will copy-paste the code and will forget where he committed mistake.:angry:
Did you tried explaining him where he went wrong
Please note:
I know no one gets paid to help here. I even know that you can debug the flawed code very quickly and repost it. But the real pain lies in explaining the things to the new-bie so that he can get meaning to your code.

So now regarding the code tyoung4@runner
look at for (hours = 1; hours <= mph; hours++) . You already had some value in hours which you took from user, right? And look what you did, you made the hours=1 which mean that the previous value has been lost!. So, rather use what tux4life did.

Moreover, I dont think the second statement of

cout << " ---------------------------------- " << endl;
cout << hours << "\t\t" << distance << endl;

means anything.

Also, dont use system("clear") . Why? Because using system() makes your code unportable. For eg: On windows you use system("cls") while on Linux, you will have to use system("clear"); So take it from me, don't use system()

tux4life commented: You made a good point here! +1
siddhant3s 1,429 Practically a Posting Shark

You are actually doing crime here but letting the compiler generate the copy constructor and the assignment operator,
Look closely what Inst = A(4); do(sorry Comatose, I am answering that):
On the right side of the assignment operator, a temporary object is created, a copy constructor is called which copy the value of all the member of that temporary object to Inst and then, listen up, call the destructor of that temporary object.
Now as the destructor deletes the memory assigned to Int, the value of *Int is shown as zero(actually it is undefined). Now again as you program terminates, the destructor of Inst is called, which tries to delete a pointer which is already passed to delete once. And so, your program gets screwed up( the second delete, actually throws an exception, which is un-catched)

.

Comatose commented: Precisely. :) +11
siddhant3s 1,429 Practically a Posting Shark

Dude, #'s are Preprocessor directives. That means all of those things are done before compiling your code.
So here how it goes.
First, the preprocessor work on all the #'s and make the code ready for compilation
it doesnt even see your code. nor does the preprocessor knows c/c++.
It understands only macros i.e. all the #'s

After the preprocessor does its job, your code is then compiled by the compiler.

So getting the point?

rmlopes commented: The only post that would have been worth at the time, in this thread +1