In: Computer Science
c++ question
Question 2: X = 7777
Modify the code below and use conditional branching (if, else,
etc.)
to print the following:
if X is between 0 and 33333 then print the word: red
if X is between 33334 and 66666 then print the word: blue
if X is between 66667 and 99999 then print the word: green
if none of the above condition matches then print the word:
white
#include<iostream>
using namespace std;
int main()
{
int x=7777;//initializing value of x
if(x>=0 && x<=33333)//condition 1
{
cout<<"red\n";
}
else if (x>=33334 && x<=66666)//condition 2
{
cout<<"blue\n";
}
else if(x>=66667 && x<=99999)//condition 3
{
cout<<"green\n";
}
else//condition 4
{
cout<<"white\n";
}
return 0;
}
Feel free to comment in order to clear your doubts