- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 6
- Posts with Upvotes
- 5
- Upvoting Members
- 5
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
Re: [QUOTE=Ancient Dragon;841451]First do the math on paper & pencil. Once you get that right then coding it will be simple. If the hours is greater than 12 just subtract 12 and the A.M./P.M. flag will be 'P'. Otherwise if the hours is less than 12 the flag will be 'A' … | |
This is my solution for generating prime numbers. With this code hopefully you can generate prime numbers with incredible speed. The generated numbers will be stored in a text file titled as "Primes.txt". I have a dual core machine, but this program does not support dual core architecture, so it … | |
Alright no more prime number generators I promise, but I had to fix the last one... This one uses the Sieve of Eratosthenes algorithm. It can generate prime numbers even faster, than the previous version. 1 million prime number in 2,331 second, ten million prime number in less than 22 … | |
Greetings! So my question is: Is it possible to create your own data type? Not a class, or a structure, that builds from predefined C++ types, but your very own. For example a 128bit integer type, or a very very long floating point data type, or a binary number type … | |
Re: Try to avoid recursive functions if you can, they can slow your program greatly. | |
Re: Without getting into details. When you compile your code, the compailer (most compailers) give you 2 exe files. The one in the "Debug" folder, and another one in the "Release" folder. You need the exe file from the "Release" folder. Oh, OK I just read tux's comment. Yeah, that is … | |
Re: I think Lerner gave you a very nice explanation. What you need is another loop. You can't do this with a single loop. You need a nested loop inside your loop. In my opinion there are two solutions for you: The first one is: you make a loop for each … | |
Re: Try with this. [code=C++] // change this in your class declaration friend istream& operator >> ( istream &, Date & ); istream& operator >> ( istream &in, Date &myDate ) { cout << "Enter three integers for day, month, year: "; in >> myDate.day >> myDate.month >> myDate.year; return in; … | |
Re: Try to avoid, system( "pause" ); if you can. It works only for windows, and it needlessly calls a DOS/Windows command. Try cin.get(); instead. Another thing you are making blocks for no reason. Making the impression each block is a branch, and after that your program will behave differently. Well … | |
Re: [code=C++] Fraction::Fraction(int, int) { int num; int denom; enterFractionValue();/// gets use to input fraction if(denom == 0) // checks to see if denom = 0 { num = 0; denom = 1; // forces a 1 to the denominator } if (num == " " && denom != " " … | |
Re: sorry - double post | |
Re: Yeah, but this is a C++ forum. :) Little help: 1 hour = 60*60 seconds = 3600secs. First you have to store the amount of seconds that can't be converted to hours. 8230 % 3600 = 1030. You store the reminder in a temporary variable, then divide 8230 by 3600. … | |
Re: [code=C++] #include <iostream> using namespace std; int main() { char ** my_arrays; my_arrays = new char * [10]; // after this you will have 10 "arrays" - pointers my_arrays[3] = new char [10]; // allocate memory for the 4th array - 10 characters for my_array[3]; - 9 can be used … | |
Re: [code=C++] #include <iostream> using namespace std; void b( char** p ) { *p = "some text"; } int main() { char *p = new char [20]; b( &p ); cout << p << endl ; cin.get(); return 0; } [/code] But, isn't it wiser to pass the pointer by reference? … | |
Re: Have you tried to use a vector? You can only get the capacity of the array by this: [code=C++]sizeof( iarray ) / sizeof( int )[/code] | |
Re: You have to delete all the branches of the tree you've allocated. You use delete to get rid of a single block of data. And delete[] - to get rid of an array of data. And if you just delete[] the root, the other branches would remain there. Maybe you … | |
Re: When you are dealing with pointers for the first time, it might be confusing, when do you need to put a star in front of a variable, and actually what it means. int* p - is a pointer of type 'int'. It can hold an address of type 'int'. So … | |
Re: How about both? You can't create programs without algorithms. Algorithms are essential tools for programming. If you want to develop a program, or solve a particular problem, you will have to need an algorithm. You can use algorithms of others, or you can come up with your own. But still, … | |
Re: [QUOTE=ithelp;815368]Just choose an index randomly and swap( i ,lengh-i+1) position[/QUOTE] [code=c++]swap(i, length - (i + 1) )[/code] But don't forget the brackets, because you would get some very funny results, especially with index 0 and 1. :) | |
Re: Computer::Computer() - This is a constructor with no parameters of the class "Computer". A constructor has the same name as its class has. // This is how would look like a constructor with a parameter. For example.[code=C++]Computer::Computer( int )[/code] A constructor is special function called, when the object is being … | |
Re: [URL="http://www.codeguru.com/cpp/cpp/cpp_mfc/pointers/article.php/c4089/"]http://www.codeguru.com/cpp/cpp/cpp_mfc/pointers/article.php/c4089/[/URL] This link might be useful. | |
Re: I don't get it. What's the point of duplicating the source array in a reverse order? You can check the beginning and the ending of the array at the same time. And you can still use the array's indexing method with strings to compare each character to another. [code=C++] #include … | |
Re: And what about white spaces and new lines? You are stuffing all the characters, one by one in a temporary character, but by doing that you are losing all the new lines and white spaces. Therefore you will get an unreadable stream of characters. It would be better to read … | |
Re: Yeah I vote for Code::Blocks too! :) Another thing, if you really want to do a favor for yourself, consider only those environments which has a debugger. It is an incredibly powerful tool. You will C :) | |
Re: You start dividing every number by 1! Every integer can be divided by 1 without remainder. Therefore you will always get "false" from your is_prime(int) function. Secondly, you are going to overflow your int value. There are thousands of prime numbers in between 1 and 2000000. And their sum is … | |
Re: [URL="http://www.cplusplus.com/doc/tutorial/operators.html"]http://www.cplusplus.com/doc/tutorial/operators.html[/URL] [URL="http://www.cppreference.com/wiki/operator_precedence"]http://www.cppreference.com/wiki/operator_precedence[/URL] | |
Re: I recognize this code, this is from 3DBuzz's tutorial. :) You did not declare the default constructor in your class. In other words you do not have declaration for the constructor with no arguments. Watch the 'public section' closely. | |
Re: Try this: [code=C++] for( list<int>::iterator itr = dob.begin(); itr != dob.end(); itr++ ) { cout << *itr; } [/code] I am not sure about the starting expression of the for loop, but as far as I know. You can declare as many arguments as you want to, as long as … | |
| Re: Put your code in between a do - while statement. Like this one: [CODE=C++] #include <iostream> #include <conio.h> using namespace std; int main() { int loop = 0; do { cout << "This is the " << loop << ". run." << endl; loop++; cout << "Do you want to … |
Re: mPayment = (P*i)/q((1-pow((1 + (i/q)),-t))); Didn't you forget to put a * after q? By the way it gives back 323,406. |