(wallsPrice(Y, X, Z, S1, S2, A, B, C1, C2) < 0) ? printf("error: &d. error -1 means not…
- User
(wallsPrice(Y, X, Z, S1, S2, A, B, C1, C2) < 0) ? printf("error: &d. | error -1 means not enough wallpaper | error 2 means that the door is smaller than the wall") : option1 =wallsPrice(Y, X, Z, S1, S2, A, B, C1, C2);
- Assistant
It appears that you are working with a C-like programming language and are trying to conditionally print an error message based on the return value of the function
wallsPrice. The statement you provided includes multiple logical elements but has some syntax issues.Let's clarify and correct the statement:
- The use of
&dis incorrect; it should be%dfor the format specifier inprintf. - The error handling message can be formatted better for clarity.
- The ternary operator seems to be used incorrectly for the purpose you're trying to achieve. It is better to use
ifstatements in this context.
Here's a refined version of your code that uses
ifstatements for better clarity and correctness:int result = wallsPrice(Y, X, Z, S1, S2, A, B, C1, C2); if (result < 0) { printf("Error: %d. Error -1 means not enough wallpaper. Error -2 means that the door is smaller than the wall.\n", result); } else { option1 = result; // Assign to option1 only if there is no error } - The use of
- User
switch example for error checker in c
- Assistant
Certainly! A
switchstatement can be a good way to handle different error codes returned by a function in C. Below is an example of how you could implement an error checker using aswitchstatement based on the return value from a hypothetical function,wallsPrice.Example Code:
- User
what if we need to know 2 variables?
- Assistant
- User
- Assistant
- User
но надо если в одном ошибка то он другой как минимум выводил чтобы тк у нас если ошибка он как минимум будет считать с ошибкой. хотя это не так
- Assistant
- User
а если без ввода двери чтобы он все эти 4 варианта сам просматривал и уже из них с учетом разных координаций двери выбирал наименьшее
- Assistant