Question

In: Computer Science

Language C++ Ask the user to enter the name of one primary color (red, blue, yellow)...

Language C++

Ask the user to enter the name of one primary color (red, blue, yellow) and a second primary color that is different from the first. Based on the user's entries, figure out what new color will be made when mixing those two colors. Use the following guide:

  • red and blue make purple
  • blue and yellow make green
  • yellow and red make orange

If the user enters anything that is outside one of the above combinations, return an error message.

Prompts:

Enter a primary color (red, blue, yellow): [possible user input: red]

Enter a different primary color (red, blue, yellow): [possible user input: blue]

Possible Outputs:

red and blue make purple

blue and yellow make green

yellow and red make orange

You entered invalid colors

Notes and Hints:

1) The program should work regardless of the color order. In other words, it shouldn't matter if the user enters red or blue first...the two colors make purple.

2) Regarding #1, this means that the first three outputs shown above may appear with the colors in a different order. Hint: Use variables in your output to make this easy!

3) If the user has any uppercase letters, it will not work. This is normal, as C++ is case sensitive. We will solve this problem in a future in-class lesson.

Solutions

Expert Solution

#include <iostream>

#include <string.h>

#include <string>

using namespace std;

int main() {

string primary,secondary;

cout << "Enter Primary Color: ";

cin>>primary;

cout << "Enter Secondary Color: ";

cin>>secondary;

if((primary == "red" && secondary == "blue") || (primary == "blue" && secondary == "red")) cout<<primary<<" and "<<secondary<<" makes purple"<<endl;

else if((primary == "yellow" && secondary == "blue") || (primary == "blue" && secondary == "yellow")) cout<<primary<<" and "<<secondary<<" makes green"<<endl;

else if((primary == "red" && secondary == "yellow") || (primary == "yellow" && secondary == "red")) cout<<primary<<" and "<<secondary<<" makes orange"<<endl;

else cout<<" You entered Invalid Colours";

}


Related Solutions

Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Language C++ Ask the user to enter their weight (in pounds) and their height in inches....
Language C++ Ask the user to enter their weight (in pounds) and their height in inches. Calculate their Body Mass Index (BMI) and tell them whether they are underweight, overweight, or at optimal weight. BMI formula: weight * 703 / (height * height) Optimal weight is a BMI from 19 to 26. Lower is underweight, higher is overweight. Prompts: Enter your weight (in pounds): [possible user input: 144] Enter your height (in inches): [posible user input: 73] Possible Outputs: Your...
6. The coolest stars are those whose color is a. blue b. red c. yellow d....
6. The coolest stars are those whose color is a. blue b. red c. yellow d. white 7. A pulsar is a powerful source of radio (and sometimes light) waves thought to be coming from a. rapidly spinning white dwarf stars b. supernovas c. spinning stars composed primarily of neutrons d. ordinary stars like our Sun which happen to be more energetic than the average 8. The existence of "black holes" has been a. verified by actual astronomical observations b....
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
The colours red, blue, and yellow are known as the primary colours because they cannot be...
The colours red, blue, and yellow are known as the primary colours because they cannot be made by mixing other colours. When you mix two primary colours, you get one of following secondary colour: -Mix red and blue: purple -Mix red and yellow: orange -Mix blue and yellow: green Write a function colour_mix that takes two strings as parameters as two primary colours and returns the secondary colour. If the parameters are anything other than "red", "blue", or "yellow", the...
The colours red, blue, and yellow are known as the primary colours because they cannot be...
The colours red, blue, and yellow are known as the primary colours because they cannot be made by mixing other colours. When you mix two primary colours, you get one of following secondary colour: - Mix red and blue: purple - Mix red and yellow: orange - Mix blue and yellow: green Write a function colour_mix that takes two strings as parameters as two primary colours and returns the secondary colour. If the parameters are anything other than "red", "blue",...
Your Application should ask the user to enter their name and their salary.
Create a C# Console Application, name the solution Homework 6 and the project TaxRate.Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric...
Write a c++ program that ask a user to enter his name and birthday (YYYY/MM/DD). If...
Write a c++ program that ask a user to enter his name and birthday (YYYY/MM/DD). If the age is greater than 21 print "welcome," and if the age is less than 21 print "sorry." Use input validation to make sure the birthdate was entered correctly.
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT