Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Wavelengths of visible light are approximately in the range of .4 to .7 microns.

ID: 3544455 • Letter: W

Question

Wavelengths of visible light are approximately in the range of .4 to .7 microns. The table below shows the relationship between color and wavelength. Write a program that asks the user to supply a wavelength. The program should use that input and the tabular values to display the color (as text) associated with the input wavelength. Any input wavelength less than .4 microns or greater than .7 microns should return an error message stating that the input wavelength is outside the range of visible light.



Wavelength range(microns)                                    color

       .400 to less than .424                                            violet

       .424 to less than .491                                             blue

       .491 to less than .575                                             green

       .575 to less than .585                                             yellow

       .585 to less than .647                                             orange

       .647 to less than .700                                              red

Explanation / Answer

 
#include <iostream> #include <iomanip> using namespace std; int main()  {  double wl=.647;   cout << "Type your WaveLength: "; //cin >> wl;  cout <<" _____" <<endl;  if(wl<0.4 || wl>0.7) cout <<"_____" <<endl; else if(wl >= 0.4 && wl <=0.424) cout << "Violet: " <<endl;  //cout <<"_____" <<endl; else if(wl >= 0.4 && wl <= 0.491) cout << "Blue: " <<endl;  //cout <<"_____" <<endl; else if(wl >= 0.4 && wl <= 0.575) cout <<"Green: " <<endl;  //cout <<"_____" <<endl; else if(wl >= 0.4 && wl <= 0.585) cout <<"Yellow: " <<endl;  //cout <<"____" <<endl; else if (wl >= 0.4 && wl <= 0.647) cout << "Orange: " <<endl;  //cout <<"____" <<endl; else if(wl >= 0.4 && wl <= 0.700) cout <<"Red: " <<endl;      //system ("PAUSE");  return 0;  } 
Output:
 
Type your WaveLength:  _____ Orange:  
 
Type your WaveLength:  _____ Orange:  
 
Type your WaveLength:  _____ Orange:  
  
#include <iostream>  #include <iomanip>  using namespace std;  int main()    {    double wl=.647;      cout << "Type your WaveLength: ";  //cin >> wl;    cout <<" _____" <<endl;    if(wl<0.4 || wl>0.7)  cout <<"_____" <<endl;  else if(wl >= 0.4 && wl <=0.424)  cout << "Violet: " <<endl;    //cout <<"_____" <<endl;  else if(wl >= 0.4 && wl <= 0.491)  cout << "Blue: " <<endl;    //cout <<"_____" <<endl;  else if(wl >= 0.4 && wl <= 0.575)  cout <<"Green: " <<endl;    //cout <<"_____" <<endl;  else if(wl >= 0.4 && wl <= 0.585)  cout <<"Yellow: " <<endl;    //cout <<"____" <<endl;  else if (wl >= 0.4 && wl <= 0.647)  cout << "Orange: " <<endl;    //cout <<"____" <<endl;  else if(wl >= 0.4 && wl <= 0.700)  cout <<"Red: " <<endl;            //system ("PAUSE");    return 0;    }  
Output:
  
Type your WaveLength:   _____  Orange: