- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 1
- Posts with Upvotes
- 1
- Upvoting Members
- 1
- Downvotes Received
- 5
- Posts with Downvotes
- 5
- Downvoting Members
- 3
10 Posted Topics
Re: [QUOTE=elsiekins;1362228]Maybe use a array to store the variables , then sort the array in numerical order then access the first and last element of the array.[/QUOTE] There are only 20 numbers. It's faster to linear search while saving the biggest and smallest as you go: [code] #include <iostream> #include <cstdlib> … | |
Re: boolalpha and noboolalpha work for cin too: [code] #include <iostream> using namespace std; int main() { bool awesome = false; cout << "Are you awesome? "; if (!(cin >> boolalpha >> awesome)) { cin.clear(); cin >> noboolalpha >> awesome; } if (awesome) cout << "You *are* awesome!" << endl; else … | |
How can this BST class be better? [code] #include <iostream> #include <iomanip> #include <stdlib.h> #include <time.h> #include <conio.h> using namespace std; template <class KeyType, class ValueType> class BST { public: BST(): mroot(0), mcount(0) {} BST(BST const& tree) { *this = clone(tree.mroot); } BST& operator=(BST const& tree) { if (this != … | |
Re: Just for division: [code] template<typename T> T reduceArray(T myArray[], int size) { if (size == 0) return myArray[0]; return reduceArray(myArray, size - 1) / myArray[size]; } [/code] | |
Re: To me it makes more sense to start from the current index and add the previous 2: [code] #include <iostream> using namespace std; int main() { int a[128] = {1, 1}; int terms; cout << "How many n terms do you want in the sequence: "; cin >> terms; for … | |
Re: Local variables are destroyed when the function returns. If you need a reference, you also need a different place to store the string so that it has a longer lifetime. | |
Re: Wrap the game in a loop. It's easier if the game is in a different function from main: [code] #include <iostream> #include <ctype.h> #include <conio.h> using namespace std; void play_game() { cout << "Playing game..." << endl; } int main() { do { play_game(); cout << "Again? (y/n)> " << … | |
Re: [QUOTE=Tahir33;1361612]no there're 7 [possible steps for 4 step tower.[/QUOTE] The problem definition is vague, but let's say the rules are like this: [list] [*]Step 0 can't be skipped [*]At any step, the next step can skipped [*]Only one step can be skipped at a time [*]The last step can't be … | |
Re: Pass by const reference if you want to accept literals: [code] myc(myc const& a, myc const& b):itsvalue(a.itsvalue + b.itsvalue) {} [/code] |
The End.