200 Posted Topics

Member Avatar for nssrsaran

#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 …

Member Avatar for Gonbe
0
2K
Member Avatar for tanmay.majumdar2

-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; }

Member Avatar for Gonbe
0
396
Member Avatar for kshahnazari

#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 …

Member Avatar for ravenous
0
117
Member Avatar for Kareem Klas

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, …

Member Avatar for PrimePackster
0
1K
Member Avatar for helloworld1234

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 …

Member Avatar for helloworld1234
0
166
Member Avatar for fsdhf_20

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, …

Member Avatar for CrazyDieter
0
167
Member Avatar for StefanRafa0

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 = …

Member Avatar for Lucaci Andrew
0
259
Member Avatar for general2012

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 …

Member Avatar for general2012
0
113
Member Avatar for MasterHacker110

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) * …

Member Avatar for MasterHacker110
0
149
Member Avatar for pooja.singh.3950
Re: code

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 …

Member Avatar for Gonbe
-1
102
Member Avatar for DarWar

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;`)

Member Avatar for deceptikon
0
197
Member Avatar for wolwayne

TL;DR. Instead of posting the entire code post only the relevant part(s) or create a small example which reproduces the issue.

Member Avatar for wolwayne
0
123
Member Avatar for brock.holman.7

int counter = 30; // "While 'counter' is going to zero". while (counter --> 0) { // Do things on every decrement, if desired. } =P

Member Avatar for Gonbe
0
138
Member Avatar for MasterHacker110

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 …

Member Avatar for Gonbe
0
136
Member Avatar for saurabh.mehta.33234

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 …

Member Avatar for Gonbe
0
157
Member Avatar for 111100/11000

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 …

Member Avatar for Gonbe
0
2K
Member Avatar for tom.scott.73113

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' …

Member Avatar for Gonbe
0
198
Member Avatar for geraldmumpuku

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 …

Member Avatar for Gonbe
0
144
Member Avatar for abdelrules

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 …

Member Avatar for Gonbe
0
235
Member Avatar for kw42chan

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 …

Member Avatar for kw42chan
0
412
Member Avatar for christodoulos14

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 …

Member Avatar for christodoulos14
0
183
Member Avatar for tadas.bareikis

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 = …

Member Avatar for Moschops
0
170
Member Avatar for chinmayi4216

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 …

Member Avatar for Gonbe
0
297
Member Avatar for Bchandaria

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 …

Member Avatar for ahmedhamdy
0
3K
Member Avatar for nitin1

> 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.

Member Avatar for deceptikon
0
618
Member Avatar for ahpple.gonzales

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 …

Member Avatar for PrimePackster
0
238
Member Avatar for marco.lanza.507

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 …

Member Avatar for marco.lanza.507
0
343
Member Avatar for marnun

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; }

Member Avatar for marnun
0
516
Member Avatar for silvercats

"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))

Member Avatar for Gonbe
0
138
Member Avatar for artur.sinelnikovs

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 …

Member Avatar for sanket044
0
147
Member Avatar for vikuseth

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 …

Member Avatar for Gonbe
0
232
Member Avatar for xxwikkixx
Re: DICE

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 …

Member Avatar for theguitarist
0
171
Member Avatar for gamnlxvi

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 …

Member Avatar for gamnlxvi
-1
213
Member Avatar for kshahnazari

#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 …

Member Avatar for Gonbe
0
146
Member Avatar for lalitha2294

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)

Member Avatar for lalitha2294
0
159
Member Avatar for clubberlangMayo

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.

Member Avatar for clubberlangMayo
0
1K
Member Avatar for Alexkid

#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 …

Member Avatar for deceptikon
0
4K
Member Avatar for prahesh

#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 = …

Member Avatar for NathanOliver
0
197
Member Avatar for rotenegg

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)); }

Member Avatar for NP-complete
0
202
Member Avatar for new_developer

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 …

Member Avatar for Ancient Dragon
0
614
Member Avatar for christinetom

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 …

Member Avatar for christinetom
0
196
Member Avatar for codeyy

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 > …

Member Avatar for Gonbe
1
3K
Member Avatar for omarking05

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 …

Member Avatar for omarking05
0
162
Member Avatar for dmo1

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 = …

Member Avatar for dmo1
0
147
Member Avatar for Grandiago

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.

Member Avatar for Grandiago
0
322
Member Avatar for Gujjar007

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 …

Member Avatar for Gonbe
0
150
Member Avatar for Cw Will

#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*"; …

Member Avatar for Adak
0
281
Member Avatar for Coach_Nate

>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.

Member Avatar for rubberman
0
261
Member Avatar for M4ver1k

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 …

Member Avatar for M4ver1k
0
276
Member Avatar for np2100

The code will be like this #include <iostream> int main () { std::cout << "Nice _quality_ necro-post.\n"; return 0; }

Member Avatar for Gonbe
0
341

The End.