Question
How would I change the return INVAILID_INPUT_ERROR to a print statement that redirects the user to input the correct input and retry the code from
How would I change the return INVAILID_INPUT_ERROR to a print statement that redirects the user to input the correct input and retry the code from that point. Also how would I add error statements for letters and negatives for both INVAILID_INPUT_ERROR and TODO?
#include
#include "colorUtils.h"
int max(int a, int b, int c) { return (a > b) ? (a > c ? a : c) : (b > c ? b: c); }
int min(int a, int b, int c) { return (a < b) ? (a < c ? a : c) : (b < c ? b : c); }
ErrorCode toGrayScale(int *r, int *g, int *b, Mode mode) { if (r == NULL || g == NULL || b == NULL) { return INVALID_INPUT_ERROR; }
switch (mode) { case AVERAGE: *r = *g = *b = round((*r + *g + *b) / 3.0); break; case LIGHTNESS: *r = *g = *b = round((max(*r, *g, *b) + min(*r, *g, *b)) / 2.0); break; case LUMINOSITY: *r = round(0.21 * *r + 0.72 * *g + 0.07 * *b); *g = *r; *b = *r; break; default: return INVALID_INPUT_ERROR; }
return NO_ERROR; }
ErrorCode toSepia(int *r, int *g, int *b) { if (r == NULL || g == NULL || b == NULL) { return INVALID_INPUT_ERROR; } int sepiaR = round(0.393 * *r + 0.769 * *g + 0.189 * *b); int sepiaG = round(0.349 * *r + 0.686 * *g + 0.168 * *b); int sepiaB = round(0.272 * *r + 0.534 * *g + 0.131 * *b);
// Reset values that exceed 255 to 255 if (sepiaR > 255) { TODO: state that the value exceeds 255 or is negative and have the user re-enter inputs; } if (sepiaG > 255) { TODO: state that the value exceeds 255 or is negative and have the user re-enter inputs; } if (sepiaB > 255) { TODO: state that the value exceeds 255 or is negative and have the user re-enter inputs; }
// Store the sepia values back into the variables *r = sepiaR; *g = sepiaG; *b = sepiaB;
// Return 0 to indicate success return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started