[Solved] Sum of digits at Even and Odd Places in C

[ad_1] Here is a solution for your problem: void main() { int n,m,oddSum=0,evenSum=0; printf(“Please insert the number for the program:”); scanf(“%d”,&n); int flag=0; int counter=1; while (n!=0) { if(counter%2==0) { evenSum += n % 10; n /= 10; } else { oddSum += n % 10; n /= 10; } counter++; } if(counter%2==0) { int … Read more

[Solved] Why is this function returning an empty vector? [closed]

[ad_1] There are several issues in your code: highestSize and add are not initialized. In C++ variables are not default initialized to 0 as you might have expected. newArray is default constructed to have 0 elements. In this case you cannot use operator[] the way you did. operator[] can access only elements that were allocated. … Read more

[Solved] Unknown piece of code, what’s it called? [closed]

[ad_1] The first line looks like an interface declaration. It is saying that a class has a method that accepts an integer and a string and returns an integer. Then it calls the method. However, this isn’t valid right now. I’m not sure if the rest was removed for brevity since you didn’t link to … Read more

[Solved] Performance: While-loop

[ad_1] I would suggest neither, rather I would suggest this List<int> data = Enumerable.Range(0, 10000000).ToList(); int j = -1; // Method 1 while (++j < data.Count) { // do something } int j = 0; do { //anything } while (++j<data.count); pre-increment operation is faster than post, although a small performance advantage 3 [ad_2] solved … Read more

[Solved] Class has no member speak? [closed]

[ad_1] void::speak(); //THE GLOBAL SCOPE HAS NO SPEAK It’s interpreting this as void ::speak() where leading an identifier (a name) with :: indicates to C++, “Look in the global scope of all names”. :: is the “scope resolution operator” In the header file, you should just use void speak(); since C++ sees it inside your … Read more

[Solved] c++ Array MEMMOVE bug

[ad_1] In your memmove call, you are using the incorrect length: memmove(s1+i+1,s1+i,strlen(s1)); strlen(s1) is the length of the string starting from the beginning and not including the null terminator. So there are two problems. First, you want the length of the string starting from the current position. Second, you want the length including the null … Read more

[Solved] Generating a perfect maze in C

[ad_1] I think the algorithms you linked will work if you expand each cell into 4 cells, and use the top, left and top left as the walls if they exist. Walls below the cell will be handle as a wall above the cell below, if that makes sense? [ad_2] solved Generating a perfect maze … Read more

[Solved] C++ Returning pointer from function

[ad_1] Yes they are exactly the same. The first code in words: SomeClass pointer sc = new SomeClass(); return SomeClass pointer sc The second code in words SomeClass pointer sc = new SomeClass(); SomeClass pointer rSc = SomeClass pointer sc return SomeClass pointer rSc As you can read/ see for yourself there is no difference … Read more

[Solved] C# programming error questions?

[ad_1] CS1955 Non-invocable member ‘pieceworkForm.calcButton’ cannot be used like a method. Instead of calling a method you are calling an event handler. What you want to do is the following: float pay = calc(pieces); CS0266 Cannot implicitly convert type ‘double’ to ‘float’. An explicit conversion exists (are you missing a cast?) You need to specify … Read more

[Solved] Memory Leak in Struct C++ [closed]

[ad_1] First, your code won’t compile with the stray “struct” in there. Deleting that, we can answer your question: it depends how the parameter was allocated, but in any case you should only do it once. int main() { int a[] = { 1, 1, 1 }; int i = 42; int* pi1 = &i; … Read more

[Solved] Transform text selected in a Textbox selected with a keyboard shortcut [closed]

[ad_1] You can use the TextBox.KeyUp event private void textBox1_KeyUp(object sender, KeyEventArgs e) { if (e.Control && e.KeyValue == 49) { if (textBox1.SelectionLength > 0) { textBox1.SelectedText = String.Format(“<h1>{0}</h1>”, textBox1.SelectedText); } } } 1 [ad_2] solved Transform text selected in a Textbox selected with a keyboard shortcut [closed]

[Solved] Delay in c# not thread.sleep [closed]

[ad_1] Yes, you can do the same thing in C#, but that is a very bad idea. This way of making a pause is called a busy loop, because it will make the main thread use as much CPU as possible. What you want to do instead is to set up a timer, and call … Read more