Question
Need help coding this fragment in C++ for this question below, just need to add this into the code without screwing everything else up, currently
Need help coding this fragment in C++ for this question below, just need to add this into the code without screwing everything else up, currently the code works fine and outputs fine but I need to add this if statement in for invalid index, I tried but it kept giving me an error please help, I have highlighted where the code should be placed as well:
Question:
It is possible that index is invalid, so remember to write an if statement to check whether or not index is invalid first. If index is invalid, then do the following:
cout << "ERROR occurred. Aborting... ";
return 1;
Sample Run:
$ ./a2.exe 0 0 0 black 0 128 0 green 255 255 0 yellow 240 240 240 white $
/////////////////////////////////////////////////////////////////////Code Below//////////////////////////////////////////////////////////////////////////////////
#include
using namespace std; // place this after the #includes
struct rgb { unsigned char red; unsigned char green; unsigned char blue; };
istream& operator >>(istream& is, rgb& colour) { unsigned r, g, b; is >> r >> g >> b; if(r <= 255 && g <= 255 && b <= 255) { colour.red = r; colour.green = g; colour.blue = b; } return is; }
ostream& operator <<(ostream& os, rgb const& colour) { os << static_cast
array
for(rgb value{}; cin >> value;) { vector
begin(colours), end(colours), back_inserter(distances), [&value](auto const& colour) { return distance(colour, value); } ); size_t index = std::numeric_limits
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