[Solved] Printing output by inside method

In your main function you are printing what the function returns, after you call it: ret = n.FindMax(a, b); //calls function with params a and b Console.WriteLine(“Max value is : {0}”, ret ); //prints out the value returned by FindMax So, to make your function print out the result, just print out the result inside … Read more

[Solved] Scanf with format specifier and input mismatch

I changed your program to #include <stdio.h> int main() { int n; printf(“%d\n”, n); scanf(“%d”, &n); printf(“%d\n”, n); } When I run it with the input “a”, it prints 32767 32767 So whatever is causing n to start out with the bit pattern for 32767, it is not anything that scanf is doing. At one … Read more

[Solved] A short C++ program about the pointer

An array of arrays like yours look like this in memory +———+———+———+———+———+———+ | x[0][0] | x[0][1] | x[0][2] | x[1][0] | x[1][1] | x[1][2] | +———+———+———+———+———+———+ The location of x, x[0] and x[0][0] is all the same. Also, arrays naturally decays to pointers to their first element. If you use plain x you will get … Read more

[Solved] Cannot figure out why my code is not working [closed]

If numberOfMiles should be of type float you have to exchange the following line scanf(“%d”, &numberOfMiles); by scanf(“%f”, &numberOfMiles); or you can set the type to int. — If you want to avoid an endless loop, exchange } while (numberOfMiles > 1); by } while (numberOfMiles < 1); Btw. why not allow distances that are … Read more

[Solved] Differences in Console class methods

String interpolation ($”this is {name1} and this is {name2}”) was introduced with C# 6. It makes it easier than doing the composite formatting (“this is {0} and that is {1}”) approach and is easier to read. The composite formatting approach leaves room for errors by having the variables in the wrong order or missing them. … Read more

[Solved] switch case statment in C# with hex values

Of course you can. “Hex Values” is merely a notation for an integral type, which is a valid case label in a C# switch block. Excepting the follow-through nature of a switch block – which you are obviating with break statements – the order of the case labels does not matter. solved switch case statment … Read more

[Solved] difference between float and double data type

There are two main differences in float and double. Those are size and precision. Float – 7 digits of precision(32 bit) and 4 bytes Ex:- 0.1234567 Double- 15 digits of precision (64 bit) and 8 bytes Ex:- 0.123456789123456 You can store float value in a double variable like this double numb; float numb2 = 22.5F; … Read more

[Solved] Every time I start the project always just writes that ” THIS IS NOT VALID” even if the numbers that I give are right [closed]

You are casting (bool) valid_triangel the address of the function instead of calling it. This will always be non-NULL and the corresponding true branch of the if condition will be executed irregardless of input. (non-issue) I don’t have cs50.h installed so I wrote a quick get_double() to test your code. Removed the declaration of valid_tringel() … Read more

[Solved] How can I use lambdas with methods in C#?

you can use an expression bodied method. static double Stirling(long n) => Math.Sqrt((2 * n + 1.0 / 3.0) * Math.PI) * Math.Pow(n, n) / Math.Exp(n); This is only possible when the method executes a single statement, and in this case, we get rid of the return statement. or you can use a Func delegate … Read more

[Solved] C++ programs on Mac OS

A default macOS installation will include something that pretends to be gcc but that’s just a legacy concern so that portable programs will properly detect a compiler when you do a source install with the usual ./configure && make && make install or use a package manager like Homebrew. Xcode used to use gcc as … Read more

[Solved] Removing punctuation from string of characters [closed]

Take a look at remove_if() #include <iostream> #include <algorithm> #include <string> using namespace std; int main() { string s; getline(std::cin,s); cout << s << endl; s.erase (std::remove_if(s.begin (), s.end (), ispunct), s.end ()); cout << s << endl; } 4 solved Removing punctuation from string of characters [closed]