Write a program that inputs a wavelength value from the user and decides the color based on the following intervals:

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question
Write a program that inputs a wavelength value from the user and decides the color based on the following intervals:
Color Wavelength (nm)
Violet 380 to less than 450
Blue 450 to less than 495
Green 495 to less than 570
Yellow 570 to less than 590
Orange 590 to less than 620
Red
620 to 750
If the wavelength is greater than or equal to 750 or less than 380, the program should print It is not a visible color.
Sample output1:
Please enter a wavelength value: 567
Green.
Sample output2:
Please enter a wavelength value: 300
It is not a visible light.
Sample output3:
Please enter a wavelength value: 890
It is not a visible light.
Transcribed Image Text:Write a program that inputs a wavelength value from the user and decides the color based on the following intervals: Color Wavelength (nm) Violet 380 to less than 450 Blue 450 to less than 495 Green 495 to less than 570 Yellow 570 to less than 590 Orange 590 to less than 620 Red 620 to 750 If the wavelength is greater than or equal to 750 or less than 380, the program should print It is not a visible color. Sample output1: Please enter a wavelength value: 567 Green. Sample output2: Please enter a wavelength value: 300 It is not a visible light. Sample output3: Please enter a wavelength value: 890 It is not a visible light.
Expert Solution
Step 1
 
#include <iostream>
using namespace std;
int main()
{
    cout<<"Please enter a wavelength value : ";//message to the user.
    int wavelen;
    cin>>wavelen; //taking wavelength as input from the user.
    if(wavelen>750||wavelen<380)   //if wavelength<380 or wavelength>750 Not 
        //a valid Wavelength
        cout<<"It is not a visible light.\n";
     if(wavelen>=380&&wavelen<450)
        cout<<"Violet\n";              //if wavelength is in between 380 and less than 450
     if(wavelen>=450&&wavelen<495)
        cout<<"Blue\n";                 //if wavelength is in between 380 and less than 450
     if(wavelen>=495&&wavelen<570)
        cout<<"Green\n";              //if wavelength is in between 465 and less than 570
     if(wavelen>=570&&wavelen<590)
        cout<<"Yellow\n";            //if wavelength is in between 570 and less than 590
     if(wavelen>=590&&wavelen<620)
        cout<<"Orange\n";   //if wavelength is in between 590 and less than 620
     if(wavelen>=620&&wavelen<750)
        cout<<"Red\n";         //if wavelength is in between 620 and less than 750
}
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,