Forum: C++ Apr 7th, 2009 |
| Replies: 22 Views: 1,468 Maybe you can avoid that, I am thinking something like this.
void Convert( int& hours )
{
hours = hours % 12;
} |
Forum: C++ Apr 6th, 2009 |
| Replies: 8 Views: 318 Click on Build, then select Configuration Manager. A window will pop up, then under the "Active solution configuration" roll down the menu and select "Release". Then compile your code again, and you... |
Forum: C++ Apr 6th, 2009 |
| Replies: 8 Views: 318 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... |
Forum: C++ Apr 3rd, 2009 |
| Replies: 6 Views: 688 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... |
Forum: C++ Apr 1st, 2009 |
| Replies: 2 Views: 244 Try with this.
// change this in your class declaration
friend istream& operator >> ( istream &, Date & );
istream& operator >> ( istream &in, Date &myDate )
{
cout << "Enter three integers... |
Forum: C++ Mar 30th, 2009 |
| Replies: 5 Views: 331 About functions. (http://www.cplusplus.com/doc/tutorial/functions.html)
About cin.get(); (http://www.dreamincode.net/forums/showtopic30581.htm) |
Forum: C++ Mar 30th, 2009 |
| Replies: 5 Views: 331 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.... |
Forum: C++ Mar 29th, 2009 |
| Replies: 4 Views: 430 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; //... |
Forum: C++ Mar 28th, 2009 |
| Replies: 3 Views: 752 Your array is too small, you only allocated space for only one int element.
int* x = new int;
correct way: int* x = new int [ the amount you need ];
while ( b != 0 )
{
x[counter_x]... |
Forum: C++ Mar 28th, 2009 |
| Replies: 3 Views: 752 |
Forum: C Mar 15th, 2009 |
| Replies: 3 Views: 262 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... |
Forum: C++ Mar 8th, 2009 |
| Replies: 7 Views: 931 Thank you Vmanes! I am still confused with passing pointers. And now looking at my code, I am wondering how on earth it compiled. :D I will look into this... |
Forum: C++ Mar 8th, 2009 |
| Replies: 7 Views: 931 #include <iostream>
using namespace std;
void b( char** p )
{
*p = "some text";
}
int main() |
Forum: C++ Mar 8th, 2009 |
| Replies: 18 Views: 1,209 I agree, but he is interested in 2D arrays, so I tried to give him an example to show him, how it works. I would create a structure as well, and then go for a vector. :) |
Forum: C++ Mar 8th, 2009 |
| Replies: 18 Views: 1,209 #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];... |
Forum: C++ Mar 7th, 2009 |
| Replies: 8 Views: 925 Have you tried to use a vector?
You can only get the capacity of the array by this:
sizeof( iarray ) / sizeof( int ) |
Forum: C++ Mar 4th, 2009 |
| Replies: 3 Views: 652 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... |
Forum: C++ Mar 3rd, 2009 |
| Replies: 3 Views: 240 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... |
Forum: C++ Mar 1st, 2009 |
| Replies: 4 Views: 247 Just ignore the previous post it was improper. Sorry. |
Forum: C++ Mar 1st, 2009 |
| Replies: 4 Views: 247 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... |
Forum: C++ Mar 1st, 2009 |
| Replies: 7 Views: 310 swap(i, length - (i + 1) )
But don't forget the brackets, because you would get some very funny results, especially with index 0 and 1. :) |
Forum: C++ Feb 28th, 2009 |
| Replies: 3 Views: 243 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... |
Forum: C++ Feb 26th, 2009 |
| Replies: 5 Views: 601 http://www.codeguru.com/cpp/cpp/cpp_mfc/pointers/article.php/c4089/
This link might be useful. |
Forum: C++ Feb 21st, 2009 |
| Replies: 6 Views: 804 Well guys I didn't want to rock the boat - I understand all of your points - that is be within C++ boundaries. I got that. |
Forum: C++ Feb 21st, 2009 |
| Replies: 6 Views: 804 Thanks, but just to recap, my question is: Is it possible to create a data type which is not bounded to predefined C++ data types. I can create my own classes. but that would still rely on them. (... |
Forum: C++ Feb 21st, 2009 |
| Replies: 6 Views: 804 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... |
Forum: C++ Feb 18th, 2009 |
| Replies: 4 Views: 301 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... |
Forum: C++ Feb 18th, 2009 |
| Replies: 11 Views: 938 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... |
Forum: C++ Feb 17th, 2009 |
| Replies: 11 Views: 619 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... |
Forum: C++ Feb 17th, 2009 |
| Replies: 4 Views: 303 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... |
Forum: C++ Feb 11th, 2009 |
| Replies: 4 Views: 718 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.... |
Forum: C++ Feb 11th, 2009 |
| Replies: 3 Views: 340 Try this:
for( list<int>::iterator itr = dob.begin(); itr != dob.end(); itr++ )
{
cout << *itr;
}
I am not sure about the starting expression of the for loop, but as far as I know. You... |
Forum: C++ Feb 10th, 2009 |
| Replies: 4 Views: 576 Put your code in between a do - while statement. Like this one:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int loop = 0; |
Forum: C++ Feb 10th, 2009 |
| Replies: 5 Views: 1,145 Try to avoid recursive functions if you can, they can slow your program greatly. |
Forum: C++ Feb 10th, 2009 |
| Replies: 6 Views: 331 http://www.cplusplus.com/doc/tutorial/operators.html
http://www.cppreference.com/wiki/operator_precedence |
Forum: C++ Feb 9th, 2009 |
| Replies: 2 Views: 388 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. |
Forum: C++ Feb 8th, 2009 |
| Replies: 0 Views: 1,053 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... |
Forum: C Feb 8th, 2009 |
| Replies: 2 Views: 343 You can read about the main() function here. (http://msdn.microsoft.com/en-us/library/3ze4ytsc(VS.80).aspx) |
Forum: C++ Feb 6th, 2009 |
| Replies: 0 Views: 877 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... |
Forum: C++ Feb 6th, 2009 |
| Replies: 2 Views: 436 #include <iostream>
using namespace std;
int a = 3;
int b = 4;
int c = 5;
int * pA = &a;
int * pB = &b;
int * pC = &c; |