Question

In: Computer Science

c++ question Question 2: X = 7777 Modify the code below and use conditional branching (if,...

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

Solutions

Expert Solution

#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


Related Solutions

c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire...
c++ /*USE STARTER CODE AT THE BOTTOM AND DO NOT MODIFY ANY*/ This is the entire assignment. There are no more directions to it. Create an array of struct “employee” Fill the array with information read from standard input using C++ style I/O Shuffle the array Select 5 employees from the shuffled array Sort the shuffled array of employees by the alphabetical order of their last Name Print this array using C++ style I/O Random Number Seeding We will make...
C Programming: POSIX: Producer / Consumer Modify the code below so that the Producer.c file calculates...
C Programming: POSIX: Producer / Consumer Modify the code below so that the Producer.c file calculates the Fibonacci sequence and writes the sequence to the shared-memory object. The Consumer.c file should then output the sequence. Producer.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <sys/shm.h> #include <sys/stat.h> #include <sys/mman.h> #include <zconf.h> int main() { /* The size (in bytes) of shared-memory object */ const int SIZE = 4096; /* The name of shared-memory object */ const char *Obj =...
MATLAB question! 4. (a) Modify the code, to compute and plot the quantity E = 1/2mv^2...
MATLAB question! 4. (a) Modify the code, to compute and plot the quantity E = 1/2mv^2 + 1/2ky^2 as a function of time. What do you observe? Is the energy conserved in this case? (b) Show analytically that dE/dt < 0 for c > 0 while dE/dt > 0 for c < 0. (c) Modify the code to plot v vs y (phase plot). Comment on the behavior of the curve in the context of the motion of the spring....
Use the data set below to answer the question. x −2 −1 0 1 2 y...
Use the data set below to answer the question. x −2 −1 0 1 2 y 2 2 4 5 5 Find a 90% prediction interval for some value of y to be observed in the future when x = −1. (Round your answers to three decimal places.)
Modify the object provided in the code below to include a variety of overloaded operators in...
Modify the object provided in the code below to include a variety of overloaded operators in C++. Your object should have the following member variables: 1. float *arr a. A dynamic float array that constitutes the data in your myArray object. 2. int size a. The size of the array that the myArray object holds Modify the provided code to include a variety of overloaded operators Operators to overload: 1. bool operator!=(myArray& obj2) a. Tests to see if the calling...
4.10 Branching Practice 2 - Python Exercise #Write the code for the following #Exercise 1 #Ask...
4.10 Branching Practice 2 - Python Exercise #Write the code for the following #Exercise 1 #Ask the user to input a name using an input statement (no prompt) and assign it to a variable #Condition: user input is equal to 'Joseph' #Action: display the user input on screen #Exercise 2 #Ask the user to input his/her first name using an input statement (no prompt) and assign it to a variable #Condition: user input is equal to 'Joseph' #Action: display the...
Below are the control strategy of hydraulic hybrid vehicle. How can I modify code below to...
Below are the control strategy of hydraulic hybrid vehicle. How can I modify code below to include the torque of motor of hydraulic hybrid vehicle? and How can I improve this function [SOC,k,T_engine,S_engine,T_brake,T_pump] = strategy(duration,gamma,P,V,Pmin,Pmax,Vmin,Vmax,SOC,Disp,T_wheel,S_wheel,gearratio,S_map,Te_max,T_engine,S_engine,T_pm,k,eff_mech,eff_hyd) S_flywheel = S_wheel*gearratio; T_flywheel = T_wheel/gearratio; T_brake = 0; if SOC < 0.1 k=1; %Engine on elseif SOC > 0.7 k=0; %Engine off end %T_pump +ve = charging %T-pump -ve = discharging if k==1 if T_engine*eff_mech < T_flywheel    %Engine provides full torque when hydraulic...
C Programming Please modify this code to display the "guess" value from the calculation and the...
C Programming Please modify this code to display the "guess" value from the calculation and the "iterations" it took to complete. Please also add the input to the program. Input: Program will prompt the user to provide the desired decimal-place accuracy, in the range of [1-15], inclusive. User prompt must clearly indicate what is a valid input. User input must be validated - ensuring that the value entered is an integer in the above range. Sample output for one perfect...
Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would...
Below is my code, Replace the 2 static_cast codes to a simpler C++ code. I would like to find another way to compile the program without using static_cast in my code. Thank you #include <iostream> #include <iomanip> using namespace std; class Population { private: int population, birth, death; public: Population() { population = 2; birth = 0; death = 0; } Population(int x, int y, int z) { if (x < 2) population = 0; else population = x; if...
Please use C language to code all of the problems below. Please submit a .c file...
Please use C language to code all of the problems below. Please submit a .c file for each of the solutions, that includes the required functions, tests you wrote to check your code and a main function to run the code. Q2. Implement the quick-sort algorithm.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT