200 Posted Topics
![]() | Re: #include<iostream> using namespace std; int CountVowels (const string text) { const string VOWELS = "aeiou"; if (text.length() == 0) { return 0; } else { if (VOWELS.find(tolower(text[0])) != string::npos) { return CountVowels (text.substr(1)) + 1; } else { return CountVowels (text.substr(1)); } } } int ArraySum (const int array[], const … |
Re: -edit- no idea what you wanted "re" to return so it returns "nothing".. #include<iostream> using namespace std; int re(int a) { cout << a << endl; if (a > 0) { re(a - 1); } } int main() { int a; cout<<"enter number\n"; cin>>a; re(a); return 0; } | |
Re: #include <iostream> using namespace std; // 3x3 Matrix const int MATRIX_SIZE = 3; void SetElement (const int row, const int column, const int value, int matrix[][MATRIX_SIZE]) { // Only set the element if the supplied indexes are valid. if (row >= 0 && column >= 0 && row < MATRIX_SIZE … | |
Re: Adding to what's already said, here's a description from the specification (section 6.6.3): A function returns to its caller by the return statement. A return statement without an expression can be used only in functions that do not return a value, that is, a function with the return type void, … | |
Re: You're returning a bool, which can only be true or false. I'm not sure what your teacher wants, but it seems to me you only have to check whether or not a specified number is part of the array. (Or print the index from the function, but that seems like … | |
Re: A cheesy way would be to brute force, you'd end up with something like this: #include <stdbool.h> #include <stdio.h> #include <math.h> // The treshold mentioned in the exercise. #define TRESHOLD (0.0001) // Test number. #define N (0.123456789) int max (const int l, const int r); bool solve (const double n, … | |
Re: You could use the fail/badbit state flags to see if there was an error. So something like this: #include <iostream> #include <limits> using namespace std; int main() { int number = 0; bool error = false; do { cout << "[?] Enter a number: "; cin >> number; error = … | |
Re: There's multiple things I'd change. First of all you're asking for input outside of the do-while loop you have in "choice". The user won't get the chance to re-enter input. I've moved that inside it. Then, the head of your linked list is created on the stack in main, while … | |
Re: Do you mean something like this? (No idea if encryption is right. Just made whatever you did apply to the whole string) #include <iostream> #include <string> using namespace std; // prime numbers int p, q; //compute int n ;//= p * q; //totient int phi;// = (p - 1) * … | |
Re: I think you missed a part of your function on copy pasting. But your function seems alright except that it doesn't state base cases which results in it not always returning something. (although behaviour is undefined I think.. it might) Anyway, something like this should fix it: int power(const int … | |
Re: If I understand your question I don't see why you would want something like that. But a constructor is called when an object is created. So create a loop that iterates 37 times and create an M_48 object every iteration by calling the default constructor. (`M_48 value;`) | |
Re: TL;DR. Instead of posting the entire code post only the relevant part(s) or create a small example which reproduces the issue. | |
Re: int counter = 30; // "While 'counter' is going to zero". while (counter --> 0) { // Do things on every decrement, if desired. } =P | |
Re: What are you using to do it right now? You can look into the sscanf function and/or the strtok function for this purpose. At a quick glance these will probably be sufficient and you don't have to create a custom solution. Can you post a minimal example of your split … | |
Re: Using the the "%%" in the format string is the only good solution as far as I'm concerned. The function itself states that this should be used to print a single '%' symbol; it makes no sense to create all sorts of more complex constructs to do something that can … | |
![]() | Re: I'm not familiar with Rail Fence cypher but at a first glance your code is full of odd things. Without knowing what rail fence cypher is or how it works I think I do understand what you are trying to do and I tried to correct it. Added some comments … |
Re: There is indeed something wrong with your logic. I've fixed your code and added comments that show what the code is supposed to do. If anything is unclear after looking at it let me know: #include <iostream> #include <iomanip> using namespace std; // Note: If you don't know what 'const' … | |
Re: Managed to get rid of the compiler errors. Compiles without warnings too. #include <iostream> #include <string> using namespace std; int main(int argc, char *argv[]) { string name; cout << "What is the person's name?"; cin >> name; cout << "Interesting! Thanks for letting me know. Don't forget to visit our … | |
Re: Also,when u declare char,u may declare like this char choice[2],then in the if else,u may do like this, if (choice[0]=='c') s0 the program will go check to that char And then you would simply not use the second slot of the array? I can't think of any reason why you … | |
Re: A function prototype is also called a function declaration. You supplied a function definition. In addition you don't follow the description. You function returns nothing while the description mentions it has to return the largest of the two. The function prototype would be: // Precondition: <add> // Postcondition: <add> int … | |
Re: This is incorrect: pina = (int **) malloc (sizeof(int *) *c); pinb = (int **) malloc (c* sizeof(int *)); pinc = (int **) malloc (c* sizeof(int *)); 'c' is 'm' times 'n' so you're dynamically allocating an array of m*n pointers to integers. You're never allocating the things these should … | |
Re: Your code is difficult to read due to the poor naming of variables and the complete lack of comments. Aside from that it just doesn't make much sense. Trying to make sense of it I added some comments: #include <stdio.h> #include <stdlib.h> #include <ctype.h> int main(void) { int a = … | |
Re: Hi. I'm a wise daniweb member and as such I'd like to inform you that we do not do your homework here as stated in the rules. Ofcourse this has been mentioned by 3 other people in this thread already making this completely redundant but my calling as an enforcer … | |
Re: Something like this? #include <stdio.h> #include <assert.h> void DrawSpiralLine(const int n, const int line) { // Throw an assertion when faulty parameters are supplied. assert(line >= 0 && line < n && n > 0); const int square = n * n; int i = 0; // Simple case: The … | |
Re: > and i wonder if you can do it. :-) I have little doubt that I could, but I don't think I will just for the sake of proving you wrong. I've removed the downvote though even though the point made stands; christmas magic, I guess. | |
Re: Something I made for a similar question in "C". Checks lines of text as opposed to words. #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <stdbool.h> #include <ctype.h> bool IsPalindrome (const char *string, const int size) { assert (size >= 0); // A word consisting of one letter or less is … | |
Re: Hi, I'm not sure where to start so I'll start from the beginning and type as I go through your code. When checking your command-line parameters you have a series of if statements, but entry of one does not lock out the rest; this is undesire in your case as … | |
Re: There is no need for additional variables. #include <iostream> #include <string> #include <cctype> using namespace std; bool isVowel(const char symbol) { return (string("aeiou").find(tolower(symbol)) != string::npos); } bool containsVowel(const string text) { return ((text.length() > 0) && (isVowel(text[0]) || containsVowel(text.substr(1)))); } int main() { // Stuff with containsVowel.. return 0; } | |
Re: "isbn" is a private member and is a string. The class has an overloaded == operator so you can use that directly if (item == item2) or, if that doesn't only compare the ISBN, you can use the "same_isbn" function. if (item.same_isbn(item2)) | |
Re: As mentioned above, include string.h and replace "trainset" with "struct trainset" on line 34. Then, as far as your actual question goes: > What needs to be done to link it? You're not linked the items you created to the root node. Add root->next = first_train; Also, you're assigning names … | |
Re: nVar is converted to a double which results in a temporary variable which is an rvalue. A quick search for rvalues and lvalues [yields](http://msdn.microsoft.com/en-us/library/f90831hc.aspxl) the following definition: You can think of an lvalue as an object that has a name. All variables, including nonmodifiable (const) variables, are lvalues. An rvalue … | |
Re: Quick fix #include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { int input; int random; cout << " VIRTUAL DICE 1.0" << endl; srand((unsigned)time(0)); do { cout << "Enter 1 to roll and 0 to quit: "; cin >> input; if (input == 1) { // Generate … | |
Re: You'll want to check if you go out of bounds. For example, you can do this in your move function: #include <iostream> #include <stdlib.h> //For system() #include <conio.h> //For getche() #include <time.h> using namespace std; //You can modify these numbers but don't delete these constants or this starting code will … | |
Re: #include <iostream> #include <vector> using namespace std; void PrintOptions (int amount, const int coinOptions[], const int coinCount, vector<int> paid = vector<int>()); void PrintOptions (int amount, const int coinOptions[], const int coinCount, vector<int> paid) { // There's nothing left to pay! if (amount == 0) { // Show what we've paid … | |
Re: That selection is done in the application itself, right? So just ask for a student ID and display the data of the user that has that ID. (You mentioned you can read the data just fine, so looking it up should be trivial) | |
Re: i have it started but not working correctly How about you start with posting that? -edit- And don't only post it, also state what you were trying to do and (if possible) where the code differs from your expectations. | |
Re: #include <sstream> #include <iostream> int main() { const char *src = "39 04 7d"; int value; std::stringstream ss; ss << std::hex << src; while (ss >> value) std::cout << value << std::endl; return 0; } -edit- Added a return 0. (Blame deceptikon's code for lacking that, got lazy and took … | |
Re: #include <map> #include <string> #include <iostream> using namespace std; struct PoiDetails { int x; string s; }; int main() { PoiDetails oBj; multimap<string, PoiDetails> vName; // Add the contents. oBj.x = 1; oBj.s = "str1"; vName.insert(pair<string, PoiDetails>("Jhon", oBj)); oBj.x = 2; oBj.s = "str2"; vName.insert(pair<string, PoiDetails>("Ben F", oBj)); oBj.x = … | |
Re: The printf statement in main does the second? Somewhat related, I found another (iterative) fibonacci function lately that is interesting: long int fib(unsigned long int n) { return lround((pow(0.5 + 0.5 * sqrt(5.0), n) - pow(0.5 - 0.5 * sqrt(5.0), n)) / sqrt(5.0)); } | |
Re: You shouldn't assign NULL to non-pointer values; the representation of pointer values is implementation defined. For most compilers the conversion will result NULL being converted to 0 as int meaning in your case it's both NULL and 0, but again, don't do it.. #include <iostream> using namespace std; int main … | |
Re: I'd say an ".a" file. An object file typically contains object code for a single source file, while an ".a" file contains multiple of them. (It is an archive of multiple .o files) So both did not involve any linking yet. Also note that this is a static library as … | |
Re: 3 year old thread, but only noticed after already writing the below, muh! #include <iostream> using namespace std; void PrintStarLine(const int size) { if (size > 0) { cout << "*"; PrintStarLine(size - 1); } else { cout << endl; } } void PrintStarTriangle(const int size) { if (size > … | |
Re: Your question is quite vague to me. Also the assignment isn't fun enough for me to go try it and you don't provide any code whatsoever to fix. You could simply use a textfile as a database which stores the account number and password per line. Then at startup you … | |
Re: Wouldn't something like this be easier? #include <stdio.h> #include <stdbool.h> #include <string.h> bool ParsePayRate(const char *text, int* dollars, int* cents) { unsigned int consumed = 0; return ((sscanf(text, "%d.%2d%n", dollars, cents, &consumed) == 2) && (consumed == strlen(text))); } bool ParseHours(const char *text, int* hours) { unsigned int consumed = … | |
Re: That's somewhat complex for someone learning C. An algorithm I'd use for parsing these kind of formula's would be the [Shunting-yard algorithm](http://en.wikipedia.org/wiki/Shunting-yard_algorithm) by Dijkstra. The article contains example code for C too. | |
Re: A while ago I started to made a couple of simple tree-operations for a BST. It was made for C though and it wasn't quite finished yet. Function descriptions and such are missing and the final interface is missing. I also wanted to add a mechanism to add variable node … | |
Re: #include <stdio.h> #include <windows.h> void PrintTwinkleSection(const int handsomeTwinkleOffset, const char* amazingTwinkle, const int fineTwinkleLength) { int lovelyTwinkleIndex = 0; for (lovelyTwinkleIndex = 0; lovelyTwinkleIndex < fineTwinkleLength; lovelyTwinkleIndex++) { putc(amazingTwinkle[(lovelyTwinkleIndex + handsomeTwinkleOffset) % fineTwinkleLength], stdout); } } int main (void) { const char* BEAUTIFUL_TWINKLE = "_,.-'-.,_"; const char* ANGELIC_TWINKLE_TEXT = "*T*W*I*N*K*L*E*S*"; … | |
Re: >hey ####tards, I wanted to know if I could parse a single integer from a string that contains multiple substrings** and integers -.- Hey clown. Glad to hear you no longer want to know. | |
Re: The double dollar sign is used to set address a variable variable name, right? This is not possible in C++ and in this context I don't think it's what you want. You want the address a struct member called "jimmy" here? You'd probably rather want a "name" struct member and … | |
Re: The code will be like this #include <iostream> int main () { std::cout << "Nice _quality_ necro-post.\n"; return 0; } |
The End.