[Solved] Initializing multiple variables in one line in C++

[ad_1] This code is completely wrong for what you are attempting. You are reading input as an integer instead of as a character. You are not initializing the vowel and consonant variables correctly, and not comparing var to them correctly. You are not checking for input errors. You are not handling upper-case letters. Try something … Read more

[Solved] How to enable C++ multithreading?

[ad_1] Official build of MinGW (that compiler Dev-C++ uses) has no support for standard library threads now. You can use boost::thread as a drop in replacement (API is similiar enough) or use Microsoft Visual C++, or try programming with g++ on Linux (this is what I have done recently, using a virtual machine). 1 [ad_2] … Read more

[Solved] Reaching the 3rd word in a string [duplicate]

[ad_1] The most straightforward way: #include <iostream> int main() { //input string: std::string str = “w o r d 1\tw o r d2\tword3\tword4”; int wordStartPosition = 0;//The start of each word in the string for( int i = 0; i < 2; i++ )//looking for the third one (start counting from 0) wordStartPosition = str.find_first_of( … Read more

[Solved] Initializing singleton in class instead of instance? [closed]

[ad_1] This is the non-lazy method of implementing the Singleton pattern for languages that support it. It’s perfectly acceptable to do this, especially since it’s one of the ways of implementing a thread-safe Singleton. However, if your Singleton object is expensive (see lazy initialization) to create, then it might not be appropriate to create it … Read more

[Solved] generate random password [C++]

[ad_1] You’re getting only numbers because there’s no specialization of std::to_string() for char. So when you do to_string(alphabet[random])), it converts the char to int (which returns the letter’s character code) and then converts that to a string. So to_string(‘a’) is “97”, not “a”. Instead of an array, you could use a string containing the alphabet. … Read more

[Solved] Rules for using ‘define’ [closed]

[ad_1] #define P1(x) x+x #define P2(x) 2*P1(x) int a=P1(1)?1:0; int b=P2(a)&a; after code substitution it will look like this: int a=1+1?1:0; int b=2*a+a&a; Since 1+1 is not false, a will be 1, so: int b=2*1+1&1 for clearness, I will write it with parenthesis (see operator precedence): int b=((2*1)+1)&1 which is equivalent to: int b=3&1 which … Read more

[Solved] Unable to insert mutiple values to database [closed]

[ad_1] You can’t do 2 sets of values like your trying to do with an INSERT statement. Your effectively doing: INSERT INTO Controller_Forecast(C1,C2…) VALUES(…loads of values…) VALUES(…Loads of more values…) This isn’t valid. To insert 2 sets of data, which is what it looks like you’re trying to do you can do 2 INSERT INTO … Read more

[Solved] Simple Bubble sort program. It works flawlessly about 85% of times but in some cases it doesn’t sort the list

[ad_1] You are not using bubble sort. this is a selection sort algorithm and your code is not correct. I have updated the code for the bubble sort algorithm. #include <stdio.h> #include <stdlib.h> #include <time.h> int main() { int ctr, inner, outer, didSwap, temp; int nums[10]; time_t t; srand(time(&t)); for (ctr = 0; ctr < … Read more

[Solved] How do I complete this C (assembly) character to hexadecimal and binary conversion code? [closed]

[ad_1] Three problems: No header files. You need stdio.h for printf and fileno, and io.h for read and setmode (setmode is a Windows only function; on Linux, you would include unistd.h for read). This: int main(void); Is a function declaration, not a definition. Get rid of the ;: int main(void); Finally: while(read(STDIN_FILENO, &c, ‘) > … Read more

[Solved] Regexp – Delete the one word before XXX, remove XXX too [closed]

[ad_1] Do a single regex replacement: string input = @”Hello World XXX Goodbye XXX Rabbit!”; Regex rgx = new Regex(@”\s*\w+\s+(?:XXX|xxx)”); // or maybe [Xx]{3} string result = rgx.Replace(input, “”, 1); Console.WriteLine(result); Hello Goodbye XXX Rabbit! Demo This replacement only would target XXX for removal if it be preceded by a word (one character or more). … Read more

[Solved] How can I randomly select from prewritten strings in C#? [closed]

[ad_1] You can make an array of your string value and pick the random value from array. // String array like in below format. string [] stringArray = new [] {“A”, “B”, “C”, “D”, “E”, “F”}; // Make it accordingly int ramdomNum = random.Next(0, stringArray.Length); Console.Write(stringArray[ramdomNum]); Hope this will help you. [ad_2] solved How can … Read more

[Solved] game does not allow you to win

[ad_1] The test (result != X_WON || result != O_WON || result != DRAW) is always true, since result can’t be equal to all 3 values. result should be initialised to UNFINISHED and the test changed to: (taken != 9 && result == UNFINISHED) 0 [ad_2] solved game does not allow you to win