1,608 Posted Topics
Re: Line 9 and 16 of the code in post #3 are the first lines of function definitions and should not be terminated with a semicolon. Function declarations are terminated by a semicolon, but they aren't followed by a function body (the stuff between the {}s after the first line of … | |
Re: An alternate method that doesn't rely on using an array to hold each value read in and doesn't use some large number for the initial value of min would be to assign the first value entered to the variable holding smallest value entered. Then with each subsequent value entered compare … | |
Re: 1) Try adding a return statement in double calculate(.....). 2) If you don't have an list of header files in your program, you should have. 3) When you call the function called calculate from the function called main, you should a list of arguments enclosed in parenthesis after the name … | |
Re: >>2. Which of the numbers is larger may change during the calculation. Make sure to check which is larger every time through the loop (every time functionB() is called). This isn't necessary. The determination of largest and smallest only needs to be made once for each set of inputs as … | |
Re: You never increment i or num each time you go through the loop. Remember, trying to divide by 0 will cause problems! Given the requirements of the project I'd read the entire file into a container, then I'd loop through the container to add all the grades and divide by … | |
Re: The string/loop approach is probably the best at this point, however, you need some mechanism to add two values together, which I think is what Zandiago was trying to point out. I'd recommend taking a step few steps back and try answering each of the following questions one at a … | |
Re: To me, when doing C/C++: 0 would digit zero, that is, a numerical value. '0' could be the character capital oh or the character zero. For example: char word[10] = "Oxford"; char number[10] = "01234"; Depending on typeface used 'O' may look exactly like '0' making it difficult to tell … | |
Re: namespace is a keyword in standard C++ that indicates a container of information. For example, namespace std contains all the standard header files such as iostream, cctype, string, cmath, etc and their contents such as cin, cout, and the int, float, char types, etc. You can declare your own namespaces … | |
Re: Welcome to Daniweb! Unfortunately your post is quite vague. Do you want to print the contents of a linked list somewhere (screen, output file, printer, other) or do you want to store the contents of a file in a linked list and then print that somewhere? | |
Re: >> it's now saying that my case statement's are illegal It looks like you're missing a }. >>how to modify the program so that after the user calcualtes the volume of one object the program automatically goes back to the menu Put the menu lines inside the while loop, before … | |
Re: Welcome to DaniWeb! Congrats on use of code tags when posting code to this board! The use of void as the return type for main() on code posted here will earn you demerits if done over time. The return type for main() should be int because: it's the standard, even … | |
Re: 1) Welcome to DaniWeb! 2) When posting code to this board use code tags. How to use them is explained in the watermark in the message input box and in one of the "sticky" messages at the top of the board. Some of the people here won't respond to your … | |
Re: Debugging is an art in itself. To debug this type of problem I'd consider any and/or all of the following until I figured it out: 1) start commenting out one section of the if/else statements at a time to see where the second request statement is coming from, or 2) … | |
![]() | Re: Each student has a grade list, but each grade doesn't have a student list so the lists/nodes aren't mutually dependent. Therefore declare the gradeNode before the studentNode and have each studentNode contain a pointer to a gradeNode as a data member. |
Re: I'll toss a few more concerns in to the mix in adddition to those already pointed out by iamthwee. room and grad are declared as string variables but you are trying to compare them to a literal characters when doing things like room == 'R'. Change the declaration of room … ![]() | |
Re: Add a call to cin.get(); just before the call to return 0; in main() to try to hold the program open for viewing. Better yet, use two calls to cin.get(), or do as I do, which doesn't seem to be the mainstream, and call >> on a dummy variable just … | |
Re: Welcome to Daniweb. I see that Wolfpack helped formating your code since it was your first post. In the future please use code tags when posting information, like code, where you want to preserve indentation. As another alternative you could use the array and a loop to read through array … | |
Re: shannonpaul: Control loops come in three varieties: for, while, and do/while. Each loop has one or more keywords (telling what type of loop it is), a body (usuallly telling what to do each time through the loop), and a conditional (indicating when or how often or how many times the … | |
Re: 1) Welcome to DaniWeb! Please use code tags for future posts with code or indentation you wish to preserve. 2) Please describe what problem you are experiencing. Does the code you post not compile? Does it compile but not run? Does it run but give erroneous output? Do you get … | |
Re: revenge2: In addition to Salem's corrections please note that the << operator is for ostreams like cout and >> is for istreams like cin. Unfortunately you are calling << on both cout and cin. mypopope: The compiler/linker need to see either a function declaration (prototype) or a function definition before … | |
Re: To be able to help you best we need to know what tools you have available. For example if you don't know the first thing about the Standard Template Library then Ancient Dragon's solution isn't going to help much. If you don't know STL then you'll need to use dynamic … | |
Re: To get to your direct question, there is no good way to delete a element from an array. You could: 1)add a flag to the struct indicating that the current struct can be used or not. 2)or you could overwrite the struct you wish to delete and shift all structs … | |
Re: int swap=matrix[m][k]; cout<<""<<swap[m][k]; In line one swap is declared as an int and is initialized with an int value. In line two swap is used as a 2 dimensional array. swap can't be both an int and a 2 dimensional array. swap was declared as an int and never as … | |
Re: [code] int CelciustoFahrenheitInput() { //drop the int in the next line. //you want to call the function here //what this line is doing as written is declaring a function prototype int CelciustoFahrenheit(); } [/code] In addition, it would work best to pass the value of c obtained in that function … | |
Re: [code] void Money::input (istream& ins) { cout<<"\n\nYou are going to set up the amount for your_account"<<endl; cout<<"Enter the amount to your_account: "; bool negative; char first_character; char decimal_point; if (first_character=='-') { negative=true; ins>>first_character; } else negative=false; if(negative) { ins>>dollar_amount>>decimal_point>>cent_amount; [/code] cin is a global istream object that is predeclared for … | |
Re: >>I'm really getting lost, when making the loop to have the user put in the 10 names, you would do something like for (int i=0; i<11; i++) Not quite. Use your fingers to count starting at, and including, zero and going through, and including 10. How many numbers did you … | |
Re: [code] /*If you don't use {} after a control statement (for, while, do/while, if, etc) then the body of the statement will be just the first line after the statement. To have more than one line in the body after the statement enclose all the lines you want in the … | |
Re: As I understand it, the file random.dat already has 1000 values between 10 and 100 before you run this protocol. Now you want to read random.dat and determine what unique values between 10 and 100 are present in random.dat. To know whether the current value is unique you will need … | |
Re: One or the other or a combination of these suggestion may be helpful [code] fstream OutputFile; //try removing the ios::app mode until you can write to file in the first place OutputFile.open("Notes.txt", ios::out|ios::app); if (!OutputFile.good()) { MessageBox(hwndContainer, "There has been a problem opening the file", "File error", MB_OK); } //try … | |
Re: Presumably Edit1->Text is a string of some type. Assuming this is a Windows based program, then it's probably a C style string. If that assumption is correct then each letter in the string can be accessed by using the [] operator, like this: Edit1->Text[x]; where x ranges from 0 to … | |
Re: [code] class testCase { public: int caseId; int matrix[cellId][freq]; testCase::testCase(int i, int *matrix2[][2], float mFit) { this->caseId=i; this->matrix[cellId][freq]=*matrix2[][2]; this->fitn=mFit; [/code] I see no reason to be using the scope operator in the above snippet since the definition you are coding is occuring within the declaration. Using the this pointer is … | |
Re: Are you sure you can assign a variable of type char to a variable of type string? | |
Re: Since this is probably a learning experience in how to manipulate data rather than scrounging the archives of the Standard Template Library, I would suggest you consider this: Using the JAY example if you did this: JAY JYA AJY AYJ YJA YAJ and note that you can get all permutations … | |
Re: Goal: Reverse words in a sentence without destroying sentence and without using STL. Assumptions: 1) Input sentence not longer than 6400 char 2) Less than 81 words per sentence 3) Each word less than 81 char long 4) Output is a sentence with words reversed [code] #include <iostream> #include <cstring> … | |
Re: 1) use code tags when posting code to this board 2) You don't need these: time_t t; time(&t); yl; cls; so I'd get them out of there to avoid polluting the landscape. 3) Don't use the return value of eof() to control loops. Sooner or later it's going to cause … ![]() | |
Re: One way is to generate a container containing all numbers 1 to x, then generate a container filled with all fibonocci numbers 1 to x, then all numbers that aren't fibonacci numbers in 1 to x go in a third container that will contain all nonfibonacci numbers 1 to x. | |
Re: >> understanding behind arrays Without knowing what you know already this may be difficult, but here's a general presentation. Arrays are variables that can hold the information about a group of objects in contiguous memory. You can use an array almost like any other object. For example you can refer … | |
Re: Response removed---duplicated other posts so now irrelevant. | |
Re: You will need to store each value of number2 in a container as it's generated. When all the values of number2 have been generated then sort the container from high to low. Then use a loop using a counter (you could use second to do that) that ranges from 1 … | |
Re: Could you post the declaration of TfrmAmountSelector and TfrmClient please. | |
Re: Look up how to write a 2 dimensional array using dynamic memory and then how to access a given element of said array. Then write a routine as to how to access each element of a given row. Then write a routine as to how to access each element of … | |
Re: Declare a char variable to hold the math operator you want to use, then pass the operator to a switch statement where each case of the switch statement implements the desired math procedure desired based on the char passed. | |
Re: One way to do this is to store the data as it's entered so you can then analyze the data once it's all entered. Containers (for example, arrays) could be used to hold the data. If you don't want to use classes then I'd consider having several 2 dimensional arrays … | |
Re: I suspect your code compiles but provides unexpeceted output. I think it helps if you write out what you want to do first, then try to write code. I've attached a number of comments to your code indicating what I think your code is doing. If you write out what … | |
![]() | Re: do you mean something like: if((usersGuess - random == 1) || (usersGuess - random == -1)) or if(abs(usersGuess - random) == 1) |
Re: I suspect you're either reading/writing out of bounds on one of your arrrays or you have overfilled the stack. Since the latter is quiet easy to check, I'd check that first. To do it, declare randomArray on the heap using dynamic memory allocation rather than on the stack using static … | |
Re: I would think sprintf() is as much C++ as null terminated char arrays are. However, if you don't like using C style I/O and all you want to do is to see the hex equivalent of a value, not manipulate the hex equivalent of a value, then there is a … | |
Re: You could always try this syntax: vector<int> sample_array(10); if you want a vector of ints with space for exactly 10 ints and don't want to call resize(). If you find that the stuff you do in fill() and sort() aren't maintained in the vector in the calling function, then you … | |
Re: Welcome. I'm not sure how you managed to enclose your code in a pretty grey box but I hope it was that process and not your coding style that left justified every line. It is much easier to read code that is indented consistently. I would also suggest you start … |
The End.