[Solved] C# method rollDice

[ad_1] EDIT: Changed the while to a do-while, as this will always execute once, regardless of the initial value of a or b. It’s up to your preferences if you want to do it like this or with a while. Next to that, I have changed the parameters of the while from while (a == … Read more

[Solved] Weird behavior of a counter inside the for loop

[ad_1] 1) The array index start from 0, as per your code it will access matrice[2][2] which will cause undefined behavior. 2) matrice[a][b]=scanf(“%d”,&i); will store the return value of scanf in matrice[a][b]. #include <stdio.h> int main() { int a,b,matrice[2][2]; printf(“Put inside the matrix some numbers..\n”); for (a=1;a>=0;a–) { for (b=1;b>=0;b–) { scanf(“%d”,&matrice[a][b]); } } //Then … Read more

[Solved] C++ code malfunctioning

[ad_1] This is your search function correctly formatted: int linearsearch (int A[] , int z, int n, int srchElement) { for (int z = 0; z < n; z++) { if(A[z] == srchElement) {return z;} } return -1; } and here is how you call it: index=linearsearch(A, n, srchElement, z); You pass a value z … Read more

[Solved] Using fuctions in C

[ad_1] If you simply want to call the IsRectangle() function, just add the following code between the next: and } lines: if (IsRectangle(x1, y1, x2, y2, x3, y3, x4, y4)) { printf(“The points define a rectangle.\n”); } else { printf(“The points do NOT define a rectangle.\n”); } However, as others have pointed out, there are … Read more

[Solved] Running Program from USB drive [closed]

[ad_1] You can get the executing assembly path. string path = (new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath; From there, you can obtain the drive letter (path root): string drive = Path.GetPathRoot(path); If your file is in the same directory as the executable, you can get the file path like this: string directory = Path.GetDirectoryName((new System.Uri(Assembly.GetExecutingAssembly().CodeBase)).AbsolutePath); string databaseFile = Path.Combine(directory, … Read more

[Solved] Class level variable? [closed]

[ad_1] Because you didn’t reference the variable using an object reference in your validClientId() method (as described by T McKeown’s answer), your code is looking within the scope of the validClientId() method itself to find that variable. It can’t find it because the variable hasn’t been declared within that scope. Try including the object reference … Read more

[Solved] How to assign enum to variable

[ad_1] It’s of type FontStyle i.e. Enums are first class types. public enum FontStyle { Regular = 0; Bold =1; Italic = 2 } // No need to cast it FontStyle fontstyle = FontStyle.Bold; Edit: Perhaps you have code like this: if(1 == 1) FontStyle fontstyle = FontStyle.Bold; for your error (Embedded statement cannot be … Read more

[Solved] The Command CreateProcess C++

[ad_1] If you just want to open an existing image using defualt app then use ShellExectue API. For example: ShellExecuteW(NULL, L”open”, L”Z:\\cat.PNG”, NULL, NULL, SW_SHOW); You could also open image with mspaint using the same API: ShellExecuteW(NULL, L”open”, L”C:\\Windows\\system32\\mspaint.exe”, L”Z:\\cat.PNG”, NULL, SW_SHOW); ShellExecuteEx will let you wait for finishing process. You can do the same … Read more

[Solved] DateTime does not contain a defintion for the method and no accessible extension method accepting a first argument of type DateTime could be found [closed]

[ad_1] well the syntax was wrong, that’s all. It should be public static int CalculateAge(this DateTime bornDate). No dot between this and DateTime. But you absolutely need this when declaring an extension method, as every bit of documentation describing extension methods will say… – Jon Skeet [ad_2] solved DateTime does not contain a defintion for … Read more

[Solved] C# Convert To Decimal String Value like 0.33 [closed]

[ad_1] This should fix your problem (if I understand the problem, that is): var number = decimal.Parse(“0,55”.Replace(‘,’, ‘.’), CultureInfo.InvariantCulture); EDIT Not every culture uses the point (.) symbol as the decimal separator. If you don’t specify a format provider, the framework defaults to the current culture. I’m guessing that in this particular case, the decimal.Parse() … Read more

[Solved] Storing Char and using it in if-statements

[ad_1] [*] You could do something like this: #include<stdio.h> int main(void){ int int1, int2, sum=0; char op; printf(“Please enter one of the following Operators [*] [/] [+] [-] “); if((scanf(“%c”,&op)) != 1){ printf(“Error\n”); } printf(“Enter Value Here: “); if((scanf(“%d”, &int1)) != 1){ printf(“Error\n”); } printf(“Enter Value Here: “); if((scanf(“%d”, &int2)) != 1){ printf(“Error\n”); } if … Read more