1,296 Posted Topics

Member Avatar for sbm

There are lots of defects in this code but it works after minimal corrections. 1. Uncomment choices 2-4: replace bad function name from taxcal to tax_cal. 2. Avoid unnecessary label and goto statement. Use normal C loop in that case, for example: [code=c] for (;;) { /* input payrate_index with …

Member Avatar for sbm
0
126
Member Avatar for thuyh83

Keep it simpler, thuyh83 ;): [code=c] if (a != 0) { double d = b*b - 4.0*a*c; if (d > 0) { /* Two real roots */ } else if (d < 0) { /* Two complex roots */ } else { /* Two equal roots */ } } else …

Member Avatar for ArkM
0
165
Member Avatar for jodyf1717

A triangular array is not builtin type. It's a program (or may be application domain artifact). For example: [code] aaaa - row 0 bbb - row 1 cc - row 2 d - row 3 or a - row 0 bb - row 1 ccc - row 2 dddd - …

Member Avatar for ahamed101
0
83
Member Avatar for chococrack

Alas, it's impossible now to separate template class declaration and implementation. Why? Have a look at [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] So place all your cpp file contents into template definition header file (then wait for a new compilers generation ;))...

Member Avatar for Alex Edwards
0
188
Member Avatar for piggysmile

Have a look at the recent (solved 11 days ago) thread: [url]http://www.daniweb.com/forums/thread149945.html[/url] ;)

Member Avatar for ArkM
0
91
Member Avatar for IrishUpstart

Never use this approach in math calculations: 0.02 is a double type approximation of the real number 0.02 so 100*0.02 != 2.0. In that case you have 100 intervals (and 101 points): [code=c] double t; int i; for (t = 0.0,i = 0; i <= 100; ++i, t = i/50.0) …

Member Avatar for ArkM
0
153
Member Avatar for LADY187

Alas, M_PI constant name is not defined in the current C++ standard. For example, VC++ defines it (in <math.h> header - <cmath> is a wrapper for it) only if _USE_MATH_DEFINES macros is defined at the moment of <cmath> compilation. Well, define your own pi if you wish: [code=cplusplus] #if !defined(M_PI) …

Member Avatar for LADY187
0
107
Member Avatar for rob_xx17

If your data file contains numbers only, no need to read it in line by line manner: use fscanf directly: [code=c] double x; int rc; ... for (int n = 0; (rc=fscanf(f,"%lf",&x)) == 1; ++n) { /* you have got the next number... */ } if (rc == EOF) { …

Member Avatar for ArkM
0
318
Member Avatar for Superstar288

Well, you have three how-to problems: 1. Detect the word: it's the simplest problem - see code stub below 2. Select the word (detect end of word): see code stub below... 3. Detect a number of occurences of every word (make the dictionary): it's much more harder task. You need …

Member Avatar for ArkM
0
111
Member Avatar for marcosjp

The sprintf does not implement itoa functionality (radix in 2..36 range). Fortunately, it's so simple to get itoa portable solution: [code=c] /* The Itoa code is in the puiblic domain */ char* Itoa(int value, char* str, int radix) { static char dig[] = "0123456789" "abcdefghijklmnopqrstuvwxyz"; int n = 0, neg …

Member Avatar for ArkM
0
9K
Member Avatar for massivefermion

It's cool!.. What is it: a new character in C++? Can you post an example of this animal?

Member Avatar for Alex Edwards
0
136
Member Avatar for hezfast2

Reread overloading specifications then have a look at your overloaded operators. Overloaded operator + must return CollegeCurse (what's a strange idea ;)) and overloaded operator / must return double (why "also"?)...

Member Avatar for ArkM
0
91
Member Avatar for obsolucity

Probably you have a wonderful talent to work on the project before it's started. It's a pity I don't know how to do that... Well, define a class with back (to parent object) link (up pointer) and std::vector of down links. After that create root node then start to scan …

Member Avatar for ArkM
0
498
Member Avatar for lanilonzo

Allow me to paraphrase your help request: I have a program which do something but sometimes it does not do it. Any ideas?..

Member Avatar for stilllearning
0
71
Member Avatar for scotchfx

It's not a scope error: ipaddr is in scope from if clause to the end of else clause. See prev post: you initialize ipaddr by (inet_addr(s) == -1) - it's eaual to false, so ipaddr == 0 after conversion false to in_addr_t. You should write: [code=cplusplus] if( in_addr_t ipaddr = …

Member Avatar for ArkM
0
84
Member Avatar for cutedipti

1000+1 fairy-tails about storage class specifiers and storage duration in C... [quote]Older systems used to make a distinction between "stack" and "heap" (e.g older IBM compatible PCs used different memory chips for "stack" and "heap", and needed special drivers to access heap).[/quote] It was extended/expanded memory, not a heap. The …

Member Avatar for Narue
0
208
Member Avatar for mypopope

Don't waste a time and bandwidth to get freezed Dev-C++ or 400 Mb Visual Studio 2008 Express. Download compact Code::Blocks IDE with MinGW compiler (g++ Winsows port).

Member Avatar for ArkM
0
142
Member Avatar for rkumaram

1. The 1st problem is undefined. Please, explain what you need: do you want to access private member arrays from the outer world? If so, why you declare these arrays as private? I can't understand your (sub)question "how can I use [] operator for my use, something like following,". No …

Member Avatar for ArkM
0
150
Member Avatar for unbeatable0

Just imagine that all your numbers are scaled. For example, let 1 is equal to 1 billion, 2 == 2 billions and so on (append nine zeroes when printing)... What's a pleasure to summarize very BIG numbers with short int arithmetics: no need in GMP and other stuff... ;)

Member Avatar for dmanw100
0
129
Member Avatar for TheBeast32
Member Avatar for Narue
0
126
Member Avatar for skvikas

The std::set is an intrusive container: it has its own copies of inserted elements. So the program creates three incarnations of class Stone: one obtained from new op and the 2nd allocated in the container member and the 3rd in stones variable . The 1st object does not deleted (you …

Member Avatar for ArkM
0
87
Member Avatar for skvikas

You must define overloaded assignment operator and copy constructor for the class ChainMesh. Default assignment and copy constructor are not valid for this class. If you assign this class variables or pass them as arguments then you will deallocate memory twice with default operator= and ctor... Also check up the …

Member Avatar for skvikas
0
148
Member Avatar for staufa

Don't forget to check argc value before [icode]argv[1][/icode] using, for example: [code=c] if (argc > 1) { switch (*argv[1]) { case '1': ... break; case '2': ... default: ... } } else { /* argv[1] is NULL! */ } [/code]

Member Avatar for staufa
0
91
Member Avatar for elsa87

Is it a joke? Are you sure that it's possibble to crack a cipher if you can compose some method name like [code=cplusplus] class CrackAllTheWorld { public: bool InvokeSuperCracker(void* ciphertext) { return true; } }; [/code] Better download this article on TEA cryptanalysis topic: [url]http://cs.ua.edu/SecurityResearchGroup/VRAndem.pdf[/url] (~1.73Mb). May be it helps...

Member Avatar for ArkM
0
111
Member Avatar for killdude69
Member Avatar for rysin

Your code returns 0 (see the last statement of main ;)). It PRINTS 1. Logical expression value is true, true printed as 1 (false as 0). What's a problem? You want to print bool value - that's the value printed. If you want to print x - do that!

Member Avatar for Sci@phy
0
98
Member Avatar for srivtsan

[code=c] const int N = 6; int n1 = 1, n2 = 0; int i, k, n; for (k = 0; k < N; ++k) { n = n1 + n2; for (i = 1; i <= n; ++i) printf(" %d",i); putchar(','); n1 = n2; n2 = n; } putchar('\n'); …

Member Avatar for Aia
0
97
Member Avatar for xb211

It's suprising that you "have spent a long time trying to find library or useful class to help me perform matrix inversion". I have found then download some tested and ready-to-use freeware libraries in C++ with matrix classes and inverse operation for 10 minutes... Regrettably at the moment I have …

Member Avatar for xb211
0
144
Member Avatar for wqzerboom

OK: "array and pointers are not allowed to be used". What is it "batch"? I don't know such type (I hope, it's not an array ;)) in C++...

Member Avatar for rhoit
0
187
Member Avatar for pat7047

It's too early for start without debugging: you can't compile the source w/o errors. I think it's not only this error message was emitted by the compiler. Obviously [icode]Mortgage myMortgage();[/icode] was not recognized as a valid declaration too. May be Evan's post hits the target but stricktly speaking in this …

Member Avatar for ArkM
0
113
Member Avatar for dhingra

1. [icode]int main()[/icode] 2. Nope. For any initial i and j the loop runs until i or j comes to zero (for positive initial number - after integer overflow). Of course on 64-bit platform it's a long way to...

Member Avatar for ahamed101
0
111
Member Avatar for mbayabo

You declare local variables in if-else alternatives. Of course, they were discarded outside if-else statement: [code=cplusplus] if (a > 0 && b > 0) { // New block started Account customer(a,b); // Local variable defined (on the stack) } else { // Prev. bock is ended. Another block started. Account …

Member Avatar for chunalt787
0
140
Member Avatar for adrian116

1. It's not a constant pointer - it's a pointer to const int. You can't modify referred int value via this pointer. 2. All 10 elements of array b are short int. 3. It's a function parameter declarator (the only context where this declaration occured w/o extern prefix or initializer …

Member Avatar for adrian116
0
105
Member Avatar for rhoit

What's a problem? [code=cplusplus] typedef box<int> MyFavouriteBoxType; ... MyFavouriteBoxType b1; [/code] Look at STL headers on you C++ installation. There are lots of (useful) typedefs in STL templates...

Member Avatar for rhoit
0
2K
Member Avatar for gregorynoob
Member Avatar for VernonDozier
0
389
Member Avatar for gangsta1903

Don't forget: std::cin is not alias for a keyboard input. It's an abstract char input stream. You can attach it to a file, for example. Moreover, std::cin is not defined for windowed applications. You describe possible keyboard input errors. But std::cin does not bear a relation to online user behaviour.

Member Avatar for gangsta1903
0
147
Member Avatar for Niner710

Don't muddle yourself by a structure (or class) definition inside (or outside) another class and a declaration of a class member. The type S declared inside class X has qualified name [icode]X::S[/icode] (S at X ) and you can use this type (the type - not variable of this type) …

Member Avatar for ArkM
0
124
Member Avatar for JackDurden

Of course, you may ask the user to input size or what else. The problem is what to do with the answer. Better explain your problem, present source code snippets...

Member Avatar for Agni
0
277
Member Avatar for kevin7778

Are you sure that it's a telepathic forum? Where is a wrong line? See [url]http://www.daniweb.com/forums/thread78223.html[/url] There is a wonderful F1 key on your keyboard...

Member Avatar for stilllearning
0
64
Member Avatar for thenic

Well, it's so simple. Enclose this dialog in do-while loop then (after the calculation) ask the user if he/she want to continue then test the answer in trailing while condition. What's a problem?..

Member Avatar for kenji
0
116
Member Avatar for Dontais

[code=cplusplus] int grade; const char* reply; while (std::cout << "Enter the Students Grade [1..100]\n" "or not-a-number to quit: " << std::flush, (std::cin >> grade) && grade > 0 && grade <= 100) { if (grade < 50) reply = "F!"; else if (grade < 60) reply = "D!"; else if …

Member Avatar for Dontais
0
113
Member Avatar for Stella01

All libraries written in C?!.. Hundreds of million (or billions) lines of codes?!.. Probably you are multi-multi-millionaire: not all C libraries are freeware...

Member Avatar for Dave Sinkula
0
100
Member Avatar for jie83
Member Avatar for Niner710

It's not "a very stupid question". It's a good question. You define Blah::getValue member function outside the scope of the Blah class (you declare it inside the class definition but define it outside the class definition). The struct Values is declared inside the Blah definition so its scope is class …

Member Avatar for ArkM
0
129
Member Avatar for saneeha

Have you ever read your own posts? [url]http://www.daniweb.com/forums/thread149947.html[/url] Well, if you want the answer in this new post: no such function as getfilepathname so you can't get the path of anything from a function which is not in existence.

Member Avatar for Salem
0
106
Member Avatar for NinjaLink

That's the fateful (and typical) mistake in the average value calculations: [code=cplusplus] double average; int sum = 0; ... average = (sum / 5); // *** integer division! [/code] You try to assign the result of integer division to double value. You want to get exact average value. But 7/5 …

Member Avatar for NinjaLink
0
109
Member Avatar for pads

The std::string class has no builtin conversion to the char* type: std::string object is not a char array. It has c_str() member function - it returns const char* pointer to the string contents buffer, but don't try to modify the string text directly (that's why it's const pointer). Why you …

Member Avatar for ArkM
0
2K
Member Avatar for jared_masc

The answer to your question is so simple... it's equal to your homework complete solution. But it's your homework, not mine. Look at your original post carefully. That's the answer. Or search daniweb C (and C++) forums: there are lots of thread on this extreme popular topic...

Member Avatar for ArkM
0
113
Member Avatar for saneeha

Try _fullpath from stdlib.h (see MSDN help on this function). It has its own restrictions. If you have a file name only and know nothing about this file location you can't get its full path w/o your own search process. For example, you have 10 files named oneof10.txt in partition …

Member Avatar for ArkM
0
248
Member Avatar for mikeregas

Oh, it's much more absurd example of a recursive method than famous recursive factorial! It's rather rough C++ to C translation. Slightly better one: [code=c] int recursivePalindrome(const char *str, unsigned int index) { unsigned length = (str?strlen(str):0); ... and so with obvious code correction [/code] ... and so on with …

Member Avatar for ArkM
0
143

The End.