1,288 Posted Topics
![]() | Re: `cout << "Scores = " << score << endl;` score is (effectively) a pointer. Your code will output a hexadecimal address. I expect you want to output each score. for (int i=0; i<7; i++) { cout << score[i] << " "; } Also, this: `for (unsigned int i=0, Total=0;` create … ![]() |
Re: Give us a sample input and the output you get. We don't know what value temp begins with. We don't know what kind of objects the variables are. We need the code that goes around this. | |
Re: This is simple geometry that you could have worked out by playing with circles on a piece of paper. Programming is THINKING first and foremost. Calculate the distance between the two central points (see Pythagoras' theorem). If that distance is more than the sum of the two radii, they do … | |
Re: On the assumption that you're intending to use this on Win32 executables, it sounds like you want to know about the internal structure of a Win32 executable. Start here: http://en.wikipedia.org/wiki/Portable_Executable and then follow the references. | |
Re: Think about what you're going to code. Identify the first thing your code will do. For example, you might decide to start by getting a four digit number from the user. Code that. Code as far as you can and then come back with your code and ask us about … | |
Re: Given that we can't see your new line 18 or the code around it, you're going to have to show us the code again. | |
Re: if (firstNumber is smaller than second number) { if (firstNumber is smaller than third number) { // firstNumber is the smallest. Do something } } | |
Re: > The issue I am having right now is my program is not running unless I give my add, sub, etc. a value. When I try to just leave them as int add; or int sub; It will not do the equation. Yes it will. You'll get some random value … | |
Re: Please rephrase the question. Make sure you include the following things: 1) What you're trying to do. 2) What the error is (which means tell us what your compiler error is; the exact words, all of them). 3) The code. Do NOT put your code on another site in a … | |
Re: If you means stopping someone doing something like this: someClass pleaseDoNotCopyMe; someClass IwantToCopy; IwantToCopy = pleaseDoNotCopyMe; // Forbid this someClass anotherCopy(pleaseDoNotCopyMe); // Also forbid this you can make a private assignment operator and copy constructor private: someClass (const someClass & theOneToCopy); // no body - forbid copy construction someClass & … | |
Re: CImg is one I often point people at. It's very easy to use; a single header file. It meets some of your needs very well, others less so, but by virtue of being a single header file it has a good stab at being cross-platform and not so reliant on … | |
Re: Very commonly, this sort of thing is because there is something left over in the input buffer. Often a '\n' or other such. If you're going to mix scanf and fgets, you need to flush the input buffer after use. This sort of thing: http://stackoverflow.com/questions/2907062/fgets-instructions-gets-skipped-why | |
Re: Look at the first digit. Check if it is less than two. Look at the next digit. Check if it is less than two. Repeat for all digits. I suggest you get the number as a C++ string, and examine each char in the string using the [] operator. | |
Re: > I am trying to understand what I did wrong? find does not return 0 when it doesn't find what it's looking for. It returns string::npos | |
Re: Look at first character. If it's not a letter, then there is at least one character that is not a letter. Stop now. If it is a letter, move on to next character. Next character: Look at it. If it's not a letter, then there is at least one character … | |
Re: `a[i]` is an object of type heapnode. `mininfinitive` looks like a long. You have not taught the compiler what the operator = means when you use it with a heapnode and a long. What are you expecting to happen? It makes no sense to say that a heapnode object (which … | |
Re: Are you supposed to be writing code to perform the operation, or are you just supposed to be writing a regular expression, or are you supposed to be writing code containing a regular expression which then calls some kind of library function that processes regular expressions? | |
Re: Every time you call `new`, you allocate some memory on the heap. Your function memLeak does this twenty times. When the function ends, all the pointers to that memory (the pointers named data1 to data20) are destroyed. The memory is still allocated. You have no way to `delete` it because … | |
Re: No matter how tempted, do not read anything about pointers that invites you to think of them as house numbers written on paper, or pigeons, or telephone exchanges, or any other distracting, broken analogy :) | |
Re: Tell us what the error is. | |
Re: You ask your operating system to show graphics on screen, using your operating systems provided libraries. You can either do it directly yourself, or you can get another set of libraries to do it for you, and you ask those libraries. C++ specifies nothing about graphics. It's all dependent on … | |
Re: Somewhere in your code you are calling a function with some bad values, and that function probably calls another, and another, and so on, until finally the function that has to deal with those bad values discovers they're bad. If you build with debugging symbols on, the error should present … | |
Re: It's not a C++ error; it's an SQL error. Get the C++ to spit out the complete query being sent so you know for sure what it's sending, and then find the error in it. | |
Re: > my main problem is how to get the length of the two arrays? Our main problem is that we don't know the whole question. | |
Re: > In Event my second constructor gets an error saying expected initializer. Would that be this code? Event::Event(int a, int b) Event::Event(int a, int b) { ArrivalTime = a; wait = b; } Looks like it says `Event::Event(int a, int b)` twice. | |
Re: How would you do it on paper? Programming is problem solving. What's the simple pattern here that tells you what to write on every line? | |
Re: This is broken in two different ways. Firstly, you are using a single char (i.e. one byte only) to try to store all the user input. This is bad. You will trash memory. You need to read up on what a c-string is (i.e. an array of char) and how … | |
Re: In C (and C++) part of the language design doctrine is that you shouldn't have to pay for what you don't use. If you don't want to use exceptions, you shouldn't have to. You, the programmer, are trusted to know what you're doing and the choice of using exceptions or … | |
Re: You'd get a better response on a .NET/Managed C++ forum - this is a C++ forum and whilst some C++ coders are also familiar with .NET and managed C++ and all that, many are not. | |
Re: Many ways. Here's one. Make the projectile a different object completely. Upon creation, it copies its location from the player. After that, it's completely independent. | |
![]() | Re: `while (readFile >> a[i])` Every time you try to write to the vector like this, you have to be sure that the element `a[i]` exists. Given that at the start, the vector is of size zero, this is not going to go well. You're trying to write to a part … ![]() |
Re: What input do you type that makes it crash? | |
Re: How much space have you allocated for the string `a`? What happens if `a` can hold, say, four characters, and then you try to write an extra 10 characters from `b` after the end of it? Something bad happens. Don't forget to allow for such things. Let's ignore that for … | |
Re: In the future, you'd do better to show us all the code. This code, for example, doesn't contain the **main** function, so we have no idea where your code starts executing and we don't even know if your code even calls the functions you've shown. | |
Re: Someone has created some (probably hideous) macros, FUNCTION and TYPE, which get applied to this code. Find them and see what they do, and your questions will be answered. If I had to guess, whoever first coded this was more comfortable in some other programming language and decided to use … | |
Re: Your loops make no sense. You ask the user to enter a value into the variable `name` which you immediately write over from file. You have a `while` loop that you break out of on the first time round. This code: if (!inputFile) { cout << "Animal not found."; } … | |
Re: First one's free. double Input(double TimeEnd, double TimeStart, double BasicPay) { double totalPayment; if (TimeStart>=1&&TimeEnd<=7) { totalPayment=(TimeEnd-TimeStart)*1.20; } else {double basicPay=(7-TimeStart)*1.20; double overTime=(TimeEnd-7)*1.75; totalPayment=BasicPay+overTime; } return totalPayment; } | |
Re: You are allowed to redefine a variable inside a deeper scope. This is commonly called "shadowing" and it's generally regarded as a bad idea. | |
Re: tanmay exists INSIDE your do-while loop, but you're trying to check for it being open OUTSIDE `while(!tanmay.is_open());` Also, you're using a very old C++ compiler and not doing yourself any favours. You can get a new, modern one for free. | |
![]() | Re: > bpath is char and have C:\myf\myapp.exe If you mean bpath is a char-pointer try `C:/myf/myapp.exe` instead. The `\` is an escape symbol but `/` is recognised as the directory delimiter under windows and *nix. |
Re: > But how does the 32767 come..? It's made of whatever random values happen to be in that memory. You're reading memory you never set to a value, so it could have anything in. If your code above is the whole program, it's just whatever was left in that memory … | |
Re: This is supposed to be written in C? The following lines of code are C++ and need to be replaced with C code. #include<iostream> #include<fstream> #include<string> using namespace std; string filename; fstream fin; cout<<"Enter a filename"< cin>>filename; fin.open(filename,ios::in); cout<<"Error while opening file "< fin.get() cout< cout<<<"------------------------------"< cout<<"ENTIRE FILE HAS BEEN … | |
Re: Can you give us a working minimal program that demonstrates the problem? | |
Re: > 'calculateGrade' : must **return** a value what do I have wrong as I'm not seeing it. See how your function `getScore` uses **return** to return a value? Where is the return value from `calculateGrade`? The instructions tell you to *return the course grade* | |
Re: "Undefined reference" means the linker cannot find the actual function code. Generally, this means that you have not linked against the right library, or that you simply haven't written the code (and sometimes that you've spelled the name of a function incorrectly). Unless the actual code of the function is … | |
Re: By definition the byte is the smallest size object that can be addressed, so you have to read the whole byte and work with that. Off the top of my head, I can't think of anything likely to be faster than the simple and obvious approach, particularly if the compiler … | |
Re: Every time you make something that runs in Code Blocks, you've also made an exe file that does the exact same thing. That's what's running. Just find that exe file and run it. | |
Re: These sound like things specific to your programming class. I've no idea precisely what's meant by "program analysis" but you probably won't be going far wrong if you identify the input from the user, the calculation to be done on the input, and the returned information to be displayed to … | |
Re: Readiing the images from file is probably taking ages. You would do better to read them all beforehand and store in memory. |
The End.